Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I’m making a new test. So far I’ve just copied an old test and here it is so far:

'@TestMethod("Verify Changes")
Private Sub WhenControlTypesAcceptedListChanges_ThenControlTypesInListChecked()
    Dim dctInputs As New Scripting.Dictionary, colResults As VBA.Collection
    Set dctInputs = CreateAndAddToInputDict(FieldToChange:="TestOptionGroup", InitialValue:=1, ChangeTo:=2)
    Set colResults = SetFields_ChangeThem_ReturnNewListOfChanges(dctInputs)
    Assert.IsTrue FieldInputsMatchResults(dctInputs, colResults(1).FieldChanges)
End Sub

So, I now want to test the new property I added where the class user can specify which controls he wants to track. I’ve buried the creation of the Form Audit object in a function. So I’m going to need to alter the property here to a particular set of controls, then change the control, then make sure that it was tracked.

Conversely, I’m going to do another test in which I will specify which controls I want to track and change a control type not in the list and make sure it wasn’t tracked.

Anyway, not to get ahead of myself, let’s get this test doing what it’s supposed to do. First I’m going to make sure I’m creating my own Form Auditor object in the test.

    Dim fa As New FormAuditor
    fa.ArrayOfTrackedControlTypes = Array(acTextBox)

This will set the only control type to be checked to the acTextBox. This will make sure that I know how to set the control box correctly. Now I have another test function which will take a dictionary of changes and apply them to an existing Form Auditor. I will use that. Also another function to set the original fields. So let’s see if this works:

'@TestMethod("Verify Changes")
Private Sub WhenControlTypesAcceptedListChanges_ThenControlTypesInListChecked()
    Dim fa As New FormAuditor
    Dim dctInputs As New Scripting.Dictionary, colResults As VBA.Collection
    Set dctInputs = CreateAndAddToInputDict(FieldToChange:="TestText", InitialValue:="BeforeValue", ChangeTo:="AfterValue")
    ChangeFields dctInputs, 0
    fa.ArrayOfTrackedControlTypes = Array(acTextBox)
    Set colResults = ChangeFields_ReturnExistingListOfChanges(fa, dctInputs)
    Assert.IsTrue FieldInputsMatchResults(dctInputs, colResults(1).FieldChanges)
End Sub

This test immediately passed. So let’s try the opposite and change a different control not in the control type list and make sure it doesn’t return any results.

'@TestMethod("Count Changes")
Private Sub WhenControlTypesAcceptedListChanges_ThenControlTypesNotInListIgnored()
    Dim fa As New FormAuditor
    Dim dctInputs As New Scripting.Dictionary, colResults As VBA.Collection
    Set dctInputs = CreateAndAddToInputDict(FieldToChange:="TestCombo", InitialValue:="BeforeValue", ChangeTo:="AfterValue")
    ChangeFields dctInputs, 0
    fa.ArrayOfTrackedControlTypes = Array(acTextBox)
    Set colResults = ChangeFields_ReturnExistingListOfChanges(fa, dctInputs)
    Assert.IsTrue colResults.Count = 0
End Sub

So here, the I am expecting the collection to be empty, that the change will not be tracked, which is the case.

I’ve just written two passing tests in a row. This is either an indication that:

  1. I have written too much code before doing the Red/Green/Refactor cycle (which is the case here)
  2. OR I am writing redundandt unnecessary tests.

So now I plan on getting back to the “Red” failing test phase. Time to move on and write another test to push myself toward the next bit of code I want to write. Next time!