Last time I had just updated a test that was failing so that it would pass.
What was happening is that the class initialize module was running and hooking the TestForm event after I was making the change because I had done this:
Dim testFormAuditor As New FormAuditor
Instead of this:
Dim testFormAuditor As FormAuditor
Set testFormAuditor = New FormAuditor
So the FormAuditor Initialize method doesn’t run in the Dim statement, but it does run in the set statement.
The Initialize method did run in the first instance, but not until I actually accessed the ListOfChanges method towards the end of the test. In any case, now I have a passing test:
Next I am moving into the refactor phase.
Since I have changed my methodology of testing, I really only need the tests right now for the FormAuditor so I’m going to delete the other tests. I am also removing the interface, FormListener, and FormIterator objects since I am just moving forward with FormAuditor and testing. Perhaps those will be added back in if they make sense later.
I am also looking at the names of the current tests to see if maybe I can make them a bit shorter. I think I may want to use the Category and/or Modult names to give more context to the method names.
If I continue with the Given/When/Then structure, I could rename the Module with the Given condition.
Ok, I’m satisfied with the new names and refactoring I’ve done, so it’s time to add the next test. Technically I should be adding a test that fails, but in this case I think it will just work if we make two changes to the field and save it each time. In other words, I expect that I will have 2 dictionary entries. Here is the new test, just copying the single change test and making two changes instead:
'@TestMethod("Count Changes")
Private Sub WhenTwoFieldsAreChangedThenReturnTwoEntryListOfChanges()
Dim testFormAuditor As FormAuditor
Dim testDictionary As New Scripting.Dictionary
Set testFormAuditor = New FormAuditor
Randomize Timer
NewForm.TestText = "New Thing " & Rnd()
NewForm.Dirty = False
NewForm.TestText = "New Thing " & Rnd()
NewForm.Dirty = False
Set testDictionary = testFormAuditor.ListOfChanges
Assert.AreEqual CLng(2), testDictionary.Count
End Sub
Next time I will test it to see if it runs and I already see a refactor I can do, but I’ll only do that after I make sure the test passes.
Until tomorrow!