Introduction |
Top Previous Next |
Unit Testing has been around for a long time under different names, but was codified by the recent eXtreme Programing practices. It refers to building support functions for explicitly testing your code to ensure it is working properly. The idea is to write special functions/classes whose only purpose is to test the rest of the code to make sure it does what it is supposed to, won't crash when fed bad data, etc.
The use of such testing functions can help you to be sure that when you make changes, everything still works as expected. There is nothing magical about unit testing - it simply represents a more formal process for ensuring that your code functions the way it should and is well behaved.
Unit Testing support libraries are designed to help the developer write and perform unit testing, and there are quite a few open source and commercial unit testing support libraries for c++. Most of these require you to create special test classes and go through some hoops in order to interface with the testing system.
JrDebugLogger takes a minimalistic approach. It provides a bare minimum of functions that can be used to specify which functions should be considered testing functions, and then can automatically invoke these functions and report their behavior using the standard JrDebugLogger output functions. Essentially you write the test functions like normal functions and just register them with the system - you don't have to derive test classes from special classes, etc.
It was my view that this minimalistic approach is appropriate for all but the largest code bases, and that the focus should be on making it as easy as possible to add testing functions to your code. Testing functions can be placed in any file, and simply require a single line registering that function, placed in that same file. No need to add code to your main procedure to inform the engine about new test cases, they are automatically discovered when compiling files.
There is no separate executable for test cases - code is part of your main executable (you can of course make your own separate compilation flag for building test version).
The normal JrDebugLogger commandline parser will automatically detect commandline arguments to perform testing of all or keyword-matching tests. Results are generated as normal, and can therefore include any information you might want to produce during your tests (ie not just errors).
An example of the unit testing support can be found in an example program. For a list of alternative testing libraries and tools, see the Related Tools topic.
Right now the output features of JrDebugLogger are geared towards the gui viewer, and are not ideal for unit testing reports; better unit test reports are next on the todo list. |