The joys of setting up a blog Faszination Klo

Unit test adventures - part 1

Published on Tuesday, February 9, 2010 11:28:23 AM UTC in Programming

Dieses Post stammt aus dem ursprünglichen "Mister Goodcat"-Blog bei Geeks with Blogs (2009-2010).

Some days ago I added a feature to an existing application, and when I was testing it, I felt that some calculations in the already existing parts of the software were wrong. After digging through the code I found that an external mathematical library is used, which was developed by a colleague some time ago. Due to its nature (being a pretty basic library), it was well-resourced with unit tests, and a short test run showed all of them succeeding.

I sat down and did some old-school pen and paper calculations, and the results clearly showed that the algorithm in question was way off. I went to see the colleague responsible for the library and it turned out that he found a groundbreaking new technique of creating unit tests that saved him quite some time during the development. Apparently, you just need to follow these three simple rules:

  1. Write a stub for what you want to test.
  2. Debug the (failing) test and...
  3. Put the result of that test run as expected results into the asserts...

Very groundbreaking indeed.

Tags: Geeks With Blogs · Unit Testing