What’s Different About This Case?
By Adrian Sutton
I’ve found that doing TDD causes me to use, or perhaps just be more aware of using, some useful debugging and programming techniques. As a side note, it occurs to me that debugging and programming in TDD are essentially the same – in either case you’re trying to fix the failing test.
So while TDDing, I find myself asking “What’s different about this case?” in a way that I can’t ever recall before. It’s easier to think like this with TDD because you have a documented, repeatable set of situations to compare between. Sometimes a change you make to fix the latest test will cause others to break and it’s then that you need to determine what’s different about the new case that needs special handling. Developing without TDD, the question I’d tend to ask is “how should this work?” which is a lot broader and harder to comprehend. I still ask, “how should this work”, but it’s usually at the start of a story where I need to get my head around what needs to be done and get an overall view of the problem. Finding the answer usually means a bunch of scribbling on notepads or whiteboards going through the possible scenarios and determining what should happen. While programming, the scope is usually reduced enough that you don’t need to scribble on whiteboards, but I do find myself going over the various cases to narrow the question down to “what’s different about this case?”.
In the end, what it means is that TDD is documenting a lot of what I would otherwise do over and over in my head and getting me to the more narrowly focussed question more quickly. It doesn’t eliminate that mental process, but it does make it easier and provides a safety net for it if I miss a case.
For the record, finding what’s different doesn’t always mean a new case altogether, usually it’s just a relaxation or restriction on the criteria for an existing code path. It’s also potentially far more useful in “soft” areas like text where there isn’t a simple rule book or process definition that you can look up to determine what should happen.
More and more I’m seeing ways that TDD makes me go faster even ignoring whether or not it leads to better code quality.