Unit Testing Redux

Thinking back over my post from a year ago, I find that the real reason for most bad unit tests is that people are trying too hard, typically for one of the following reasons:

  • Some folks have drunk the "don't repeat yourself" KoolAid: I agree that not repeating code is a virtue in most cases, but unit test code is an exception: cleverness in a test both obscures the intent of the test and makes a subsequent failure massively harder to diagnose.

  • Others want to avoid writing both tests and documentation: they try to write test cases (almost invariably as "doctests") which do the work of real tests, while at the same time trying to make "readable" docs.

Read more…