TDD: I hate deleting unit tests
Following on from my post about the value we found in acceptance tests on our project when doing a large scale refactoring I had an interesting discussion with Jak Charlton and Ben Hall about deleting unit tests when they’re no longer needed.
The following is part of our discussion:
@JakCharlton @markhneedham a lot (not all) of the unit tests created can be deleted once the acceptance tests are passing…
@Ben_Hall @markhneedham yep I agree, but that isn’t what TDD really advocates - its a balance, unit tests work well in some places
@Ben_Hall @JakCharlton gotta be courageous to do that.Its like you're ripping away the safety net. Even if it might be an illusion of safety
@markhneedham one of the XP principles ... Courage :)
While Jak and Ben are probably right I do find myself feeling way more anxious about deleting test code than I would deleting production code.
I think that this is mostly because when I delete production code we usually have some tests around that code so there is a degree of safety in doing so.
Deleting tests seems a bit more risky because there’s much more judgement involved in working out whether we’re removing the safety net that we created by writing those tests in the first place.
The diagram on the right hand side shows the way I see the various safety nets that we create to protect us from making breaking changes in production code.
In this case it might seem that a unit test is providing safety but it’s now an illusion of safety and in actual fact it’s barely protecting us at all.
I find it much easier to delete a unit test if it’s an obvious duplicate or if we’ve completely changed the way a piece of code works such that the test will never pass again anyway…
..and I find it more difficult to judge when we end up with tests which overlap while testing similar bits of functionality.
Do others feel like this as well or am I just being overly paranoid?
Either way does anyone have any approaches that give you ore confidence that you’re not deleting something that will come back to haunt you later?