Wednesday, August 22, 2007

How extreme are your unit tests?

A short list of unit testing categories and tools I've seen on my journeys through legacy Java code bases in the last few years:
  • Freestyle - No unit tests, maybe the occasional ad-hoc main() method used during development.
  • Keep It Real - You believe in keeping code clean and modular, and have written unit tests for the modules using something like JUnit or TestNG.
  • Mock Me - How isolated are your modules? During unit testing can you replace the modules with Mock Objects using something like EasyMock?
  • Cover Up - You've got unit tests but what percentage of your code does the unit tests cover? A code coverage tool like Clover will tell you.
  • Attack of the Mutants - You think your unit tests comprehensively test the code? Jester makes random changes to your test code and verifies if that test still passes; so called mutation testing.
  • No Code Left Behind - Got a large chunk of legacy code that you're not sure is used? Guantanamo deletes all code not covered by unit tests.
  • Cylonification - You wrote the application first. Then you wrote some unit tests. But the unit tests were actually end-to-end integration tests. And the tests took a very long time to run. And they depended on each other. And they rebelled. And they have a plan. Ashcroft monitors and enforces discipline on your unit tests.

No comments: