Always make your tests fail

An airliner crash test

I ported some old code that I wrote in my branch of the dynamic mock packages to the new jMock codebase. Looking through the test suite I found some tests that didn't actually test anything! They just passed without bothering to check the behaviour of the object being tested. Hmmm... I must have written the test and the code to be tested at the same time, and so expected the test to pass. Which of course it appeared to do with flying colours. What a stupid thing to do. I should have written each test, watched it fail and only then written the code to make it pass.

Lesson: always make your tests fail before you make them pass.

Or, as is already written on the C2 Wiki, "never write a line of code without a failing test.

Copyright © 2003 Nat Pryce. Posted 2003-12-11. Share it.