ILoggable

A place to keep my thoughts on programming

September 10, 2007 .net , ,

TDD & you can’t test what you can’t measure

Recently I’ve been dealing with a lot of bug fixing that I can’t find a good way to wrap tests around. Which is really annoying, because it means that as things get refactored these bugs can come back. These scenarios are almost always UI related, whether it’s making sure that widgets behave as expected, or monitoring the visual state of an external application I’m controlling (Live For Speed, in this case). What all these problems have in common is that the recognition of a bug existing can only be divined by an operator, because somewhere there is lack of instrumentation that could programatically tell the state I’m looking for. And to paraphrase the old management saying, “You can’t test what you can’t measure”.

My best solution is the usual decoupling of business logic from UI. Make everything a user can do an explicit function of your model and now you can test the functions with unit tests. At least you business logic is solid, even if your presentation gets left in the cold. And depending on your UI layer, a lot of instrumentation can still be strapped on. WinForms controls are generally so rich that nearly everything you would want to test for you can probably query from the controls. But things that you can test and see within a second may be a lot of lines of code to test programatically and of course go right out the window when you refactor your UI. And if your trying to test the proper visual states of a DataGridView and its associated bindings, then you’re in for some serious automation pains.

I know that business logic is the heart of the application, but presentation is what people interact with and if it’s poor, then it doesn’t matter how kick ass your back end is. So for the time being that means that UI takes a disproportionate amount of time to run through its possible states and it’s something I would like to handle more efficiently.

Leave a comment