Unit tests

For non-trivial algorithms using the unit test program for a library can be an extremely efficient way to quickly develop functionality. Building up your logic in pieces and unit testing them as you go has the following advantages:

  • It really encourages separation of concerns.

  • The time it takes to compile, link and run the each section of code becomes exponentially faster

  • When it comes to porting to other platforms it really pays off because the unit tests which break quickly pinpoint which parts of your machinery is broken.

The alternative approach is:

  • Build up the code inside the application

  • Concerns don’t get well separated

  • When things go wrong it’s a time consuming process to identify the breakage.

    • A small change results in mysterious failures

    • The compile-link-test cycle takes a long time

    • It’s hard to see the problem in a noisy forest of tracing activity.

The symptom of the later is that project never seems to quite be done, there are always bugs and challenges, the developer doing it is usually stressed. What often happens is a negative spiral of thrashing.