Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

Back to testing:

I am currently working on this test, which I never actually completed.

'@TestMethod("FormListener")
Private Sub FormListenerRaisesBoundDataChangedEvent()
    FormListenerTest.Setup NewForm
    NewForm.TestText = "NewThing"
    NewForm.Dirty = False
    Assert.Inconclusive
End Sub

I had decided when trying to create this test that I wanted to test the functionality of the form listener. That it was raising an event whenever it heard the before update event of the form and found changed data.

As I’ve studied further, I think I am testing too far into the implementation details. What I mean is that I am not testing what I want the person using the class to see, but I am testing my own implementation of the code. This couples the tests with the implementation, meaning that if I want to separate out classes further or join functionality of classes together, this could easily break the tests.

From what I’m reading, watching, and learning. I want to test at a modular level. Perhaps I haven’t gotten far enough in for this to matter, but let’s see if I can think of something I would want to test that will test what I want the FormAuditor class to actually do.

Perhaps a a requirement like:

Given a form with bound controls, when I make a change to a bound text control, then the auditor records the change.

So I could easily create a test method with a name like:

GivenAnyFormWhenChangingBoundTextBoxThenAuditorRecordsChange()

And then I just write the ugliest, simplest code I can to get that to happen.

Let’s try this methodology now and see where it goes.

Actually, just changed my mind. How about if no changes are made, the FormAuditor returns something indicating no changes.

GivenAnyFormWhenNotChangingAnythingThenAuditorReturnsEmptyDictionary()

This puts us back at the beginning. Starting a basic test again with the main class which currently doesn’t exist yet.

'@TestMethod("FormAuditor")
Private Sub GivenAnyFormWhenNotChangingAnythingThenAuditorReturnsEmptyDictionary()
    Dim testFormAuditor As New FormAuditor
    
    Assert.Inconclusive
End Sub

This of course doesn’t compile so now I add the main FormAuditor Class containing the code:

Option Compare Database
Option Explicit

Now the test compiles. I need to add another line to the test, simply running some kind of method that will return an empty dictionary. Maybe just something like a ChangeDictionary Property. Let’s add that.

Next time… thanks for reading, and I hope you are finding this valuable. If you are let me know. If not, send me a message and let me know what you’d like to see instead.