Access JumpStart 2.0 | Blog

A Rapid Development Framework for Microsoft Access

I am trying to build a Form Auditing class using TDD. So far I’ve created a FormListener class which hooks into the Form BeforeUpdate handler. Then I created a FormIterator class which will eventually iterate through the Form object during the BeforeUpdate event and pass back form fields in a dictionary by form field name with fields that have been updated.

My last test was created to test that the FormIterator returned a Scripting.Dictionary object with no elements and I now have that passing. I considered refactoring a few things, but don’t think I can refactor things in a very useful way.

I think therefore, I need another test. So I am thinking about the next simplest thing to do. I think my FormIterator’s next simplest test is to have it return 1 field that was updated in my test form.

That is a simple test, but I have to code a lot to get to that point.

In order to pass the above theoretical test, the FormIterator needs to:

  1. get a form that is in the BeforeUpdate event
  2. iterate over all the control fields
  3. check if any of them have a Value and and OldValue that are different

So, can I write a test to get to a simpler point? I want to write the tests from a user standpoint I think. I want to ask my objects to do things and test their state to see if they were done.

So, my FormListener gets to the BeforeUpdate event already. So perhaps my FormListener needs to have a FormIterator object inside of it. Would that help me get to number 1?

Ok, so yes, I think the FormListener should use the FormIterator when it runs it’s BeforeUpdate event.

What would that test look like? Should I expose my FormIterator as a public object inside the FormListener? I would need to do that for testing, however, I don’t really need my FormListener to be told to iterate a form, it should do it automatically when executing it’s BeforeUpdate event within the context of the form. I would like the FormListener to raise an event when it has something to report, like it iterated over the form and found at least one changed field to report.

'@TestMethod("FormListener")
Private Sub FormListenerRaisesBoundDataChangedEvent()
    FormListenerTest.Setup NewForm
    NewForm.TestText = "NewThing"

End Sub

Ugh, I’m not very good at this yet and it’s making my brain hurt. The above test does not assert anything and it’s not finished. I think it’s possibly still too complex for the code I will need to write to get it to pass, so for now I’ll go rest up and untwist my brain and come back tomorrow.