Sorry, had to recognize the 007 reference with in my title. James Bond.
Anyway, I am working on a test to check whether the TestForm’s BeforeUpdate event is getting fired and the FormListener object is seeing it.
My initial thought here is to add testable responses from first the TestForm. Maybe a collection of timestamps of when the BeforeUpdate event occurs.
I’m considering making a new testable module for the TestForm, although it is literally just for our tests and will not be used otherwise.
What if I do this instead:
- Add the code to the FormListener class to hook the BeforeUpdate event of the form.
- The FormListener class could have a boolean flag to verify that it gets triggered, initially set to false
- Fire the BeforeUpdate event of the form
- Then test the FormListener boolean flag to see if it got tripped.
Hmmm… Seems like a lot of coding to get a single test to pass. But hey, I’m new at this. I’ll start setting it up and see how the testing cards fall.
I guess the first thing to do then would be to create the failing test that I want to make pass. So here it is:
'@TestMethod("FormListener")
Private Sub FormListenerHearsFormBeforeUpdateEvent()
On Error GoTo TestFail
'Arrange:
Dim FormListenerTest As New FormListener
Dim NewForm As New Form_TestForm
DoCmd.OpenForm "TestForm"
Set NewForm = Forms("TestForm")
FormListenerTest.Setup NewForm
'Act:
NewForm.TestText = "TestingUpdate"
DoCmd.RunCommand acCmdSaveRecord
'Assert:
Assert.IsTrue FormListenerTest.BeforeUpdateTriggered
TestExit:
'@Ignore UnhandledOnErrorResumeNext
DoCmd.Close acForm, NewForm.Name
Set FormListenerTest = Nothing
Set NewForm = Nothing
On Error Resume Next
Exit Sub
TestFail:
Assert.Fail "Test raised an error: #" & Err.Number & " - " & Err.Description
Resume TestExit
End Sub
I had to write a bunch of code already to get to the point where I could do the assert, but I think it’s fairly straightforward.
Next I will need to make this test pass. We’ll do that next time!