High MPG Unit Tests

How to get many useful things from unit tests

Tests add drag. No one is paying you to sell them tests, but they are a necessary chore on top of the product. Without tests high quality software is impossible to achieve, but by themselves they are useless. Tests are like custom shipping containers: adding weight, requiring maintenance and extra fuel.

Tractor pull

The good news: you can get more miles out of each gallon of tests. Here is how I stretch my unit tests:

  • Increase productivity by using Test Driven Development. I write tests, then implement features. The tests catch regressions, allowing me to implement more and more features without ever recoding features already shipped. I use code coverage tools to get away with smallest set of tests covering all features to avoid duplication.

  • Document API by serving as examples. Instead of writing lots of imprecise English in my API docs, I use xplain to transform selected unit tests to examples in my documentation. Sometimes I even skip API pages and directly update Markdown README.md file. There is also a way to use example code blocks in README.md as unit tests.

  • Keeping dependencies up to date by automatically checking if updating is possible. If you are developing using Nodejs, take a look at next-update. By running next-update inside your project that has good test coverage, you can easily see if the new dependency versions are going to break your project or not. Staying on the bleeding edge has never been easier.

    • Maybe I should extend this to bower? Let me know, should be easy.

I write my tests once, and keep them evolving with the code. I do get the triple use out of them, making it a very sound investment.

Related: High MPG Code Coverage, presentation code coverage and tests