I had a pretty “simple” change to an application in a IsLineValid function that checks the active record on a subform to see if that line is valid. A new requirement in the application meant that the conditions changed slightly.
Originally, I just added the checks directly to the code, however, I want to start doing TDD for everything. So, I’m working through the logic / work related to being able to test this “IsLineValid” function.
Initially, I was checking values right from the form itself in the test function and the test function is part of a LineController class. This means that in order to test my function, I need to instantiate a LineController class. Most of the classes functions are tightly coupled with the form, meaning they get a reference to the form to pull values directly (thisForm!Phase_Number) for example. So in order to break the dependency, I used VBA polymorphism. Here is the test which will need more modifications before it works:
RubberDuckVBA test code from my testing module:
You can see I am creating an ECI_POLineController object which is what contains the function I’m testing.
Then I’m creating a dictionary in which I will put all the field names and values which represent a valid PO line.
Now the polymorphism begins. Here I am creating an object of type “FormValueGetter_Test” which implements FormValueGetterI which just exposes 1 method: “ReadFormValue”. Here is my FormValueGetter_Test code which allows a dictionary to be set with the proper Fieldnames and values and returns the value based on the field name:
FormValueGetter_Test:
Then I had to change a few things in my LineController object:
ECI_POLineController
So, after all this, I ran into another dependency. This time I am using the “LineControlManager.LineIsConcrete” function to determine if this is a concrete based line. This function uses the LineControlManager object which uses it’s own reference to the form again and so I will need to determine how best to break this second dependency. I think that will allow me to finish writing the test.