Last Test Driven Development session I refactored the last test I did to make it easier to read and understand. I created a couple of helper functions to do this. Functions that would take specified inputs, update the fields, then test to see if the resulting audit dictionary object was the same as the inputs that were given.
I’m going to take a look at my previous tests and see if I can replace the old helper functions with these new helper functions so everything is using the same structure and everything will appear simpler.
OK, now I’m going to get started.
This was the first test I had made in this iteration of tests:
The above test doesn’t actually change any fields and it doesn’t have any helper functions… It is fine, moving on to the next test:
Ok for the above function, here we go, we do have to change a field, so I can use the inputs. I am only counting the resulting dictionary, so I don’t need to use the comparison function. Let’s see what I can do with that:
For the above changes, I realized as I started that the new function I wanted to use returned a dictionary and required at least one change to be made. This test counts the number of elements in the collection of events above the dictionary.
Therefore, I had to change the function to return the collection instead. Here’s the updated helper function:
This also meant I needed to change the latest test to use the collection instead of the dictionary so I do that as seen here (note that the only difference is in the declarations and then how I call the final assert function):
Even though I also had to further refactor, I think it is pretty good and did shorten the second test “WhenOneFieldIsChangedThenReturnSingleListOfChanges” by one line. And I was able to remove the function that just changed the value to a random new value.
So far so good. I think the next counting tests will be very easy now to refactor.