Works For You? Prove It!
By Adrian Sutton
I just stumbled across something interesting that I probably should have realized before. With TDD, the first thing you should do when you get assigned a bug to fix is write a test that reproduces it. This morning I was good and did just that, but surprisingly the test passed.
Now normally when your test passes straight off, it means you didn’t write it correctly and you need to fix the test. In this case though I could confirm manually that the bug simply didn’t happen – a classic works for me. Drop back into bugzilla and mark the bug WFM and I suddenly realized I could prove that it works correctly by pointing to the test.
So now, we have a closed bug and a passing test that will make sure it never comes back. The normal inclination I have is that the test passed straight off so it didn’t have value and shouldn’t be committed, but that’s not true. Writing a new test for an area we didn’t have a clear acceptance test1 for before is a really good thing and should be preserved. Better yet, I can point to that test in the bugzilla case and if someone disagrees they can change the test to show the problem and reopen the bug.
1 – I'd written the acceptance test first to verify the problem but didn't have a need to drill down to integration and atomic tests.↩