Practical Testing

One of the common complaints about TDD and unit testing that I see is that the examples used aren’t real. People often say that the examples used are toys and that writing such tests adds little or no value. To be honest, I often find myself agreeing with them.

Last updated 25th April 2023

41 - GoogleTest - Moving to GoogleTest.

One of the problems of adding unit tests to an existing code-base or driving a new project with TDD is deciding exactly where to spend your testing efforts. This is more of an issue when adding tests to existing code as I personally find that the safety of TDD on new code becomes slightly addictive…

Anyway, in an attempt to show how adding unit tests to existing code can be worthwhile I’ve decided to write a series of blog entries on Practical Testing of real world code…

The code I’ll be using for first examples is a class that is used by my high performance, I/O completion port based networking code, The Server Framework; The CCallbackTimer. class provides a very light-weight timer manager that runs on its own thread and is reasonably challenging to test. I have a subtle bug that I need to fix in it and reproducing the conditions that cause the bug are quite difficult; first run your PC for 49.7 days…

The class lives in one of our tools libraries and is coupled to several other classes and one other library. First I’ll present the code and the fragment of the library that’s required to use it. Then I’ll add a test harness for the library and write a simple test for the class. Then I’ll finally start working on the bug fix and some tests that prove it’s fixed and make sure it stays fixed.

I’ll use this entry as an index that I’ll update as I post the future entries.

TickShifter v0.1 - A tool that allows you to control the value returned by GetTickCount() and some sample programs built with the first and last versions of the timer queue code that demonstrate the code failing due to the original rollover bug and working once it is fixed.