Who will watch the watchers?
This kind of question is usually uttered by people in regards to authorities such as the police, intelligence agencies, governments and the like. Because, according to them, authority is bad and can’t be trusted. The problem is, it’s not so much a rational question, but a demonstration of a paradox. Tree falling in the woods kind of thing, you know?
This post is about a couple of test driven development practices, let me present them to you with their rationale:
Workflow: Red Green Refactor
The point of this is you write a broken test–run the test, make sure it’s broken. so you know the test is broken, this is very useful when you type something like assert instead of assert_equal. Kent Beck relates a story of how him and a team spent hours trying to get a test to pass, when it was the test itself that was broken. the flip side of this is that you write a test that passes when it should fail. this leads to madness, believe me.
So after you’ve gone from Red to Green, you’re free to turn that ugly implementation into something pretty–and be sure you haven’t broken it during the process, all well and good. We love refactoring, now for the other practice:
You should refactor your tests, too
You should be treating your test code with as much love and due care as you do the actual implementation. Removing duplication and stuff. I must admit it took me a while to start thinking like this, but eventually you really do start to care that your tests are nice and easy to read. I mean, that whole communicating intent kind of thing. Test should do that, so yeah.
The paradox
Here it is. We write tests to allow us to refactor our implementation safely–who or what what is going to test our tests when we refactor those? Who will watch the watchers for sure (or who will test the tests in this case).
I bring this up because I don’t actually have a good answer. We have tools like Heckle which do a good job picking up your blind spots, but does that solve this problem in particular? Is there some other practice I’ve missed? Do we strive to write good tests straight up? Does it even matter?
It’s all so confusing and arbitrary. But that’s how we like it, yeah? Nah?! Aw.
Ryan,
I understand your perspective.
As the BDD people point out, your tests are really a spec for the behaviour of your code. Whenever you are refactoring the tests you should be making them more expressive and easier to read. The easier they are to read the harder they are to get wrong.
Personally I need to see a test fail to know it is testing what I think it is, so when in doubt I comment out or modify the code and watch the test fail.
Nigel
said Nigel Thorne on September 03, 2007