Unit Testing - Registration and Invocation |
Top Previous Next |
As shown in the Unit Test Example, JrDebugLogger does not require a special testing class hierarchy.
You write your testing functions as normal global functions (or static class member functions), and then register them with the unit testing system using the following command/macro:
JrDebugRegisterTestFunction(string TestNameString,string DescriptionString,FunctionName,string Keywords); ex. JrDebugRegisterTestFunction("simpletest","Simple Unit Test",MyUnitTest,"simple");
Test functions must be declared to take no arguments and return void. You can assign a string of (space separated) keywords for a test; these keywords can be used to run only matching test functions.
The above 'function' is actually a macro that can be placed in global scope, near the test function code. This allows you to register your unit testing functions from the files that define them, without having to add registration code to your main() procedure or anywhere else. So the following would be in global scope in the file (see Example): void MyUnitTest() {dbprintf("my unit test!");} JrDebugRegisterTestFunction("simpletest","Simple Unit Test",MyUnitTest,"simple");
You may want to enclose all your testing functions in #define blocks that will not be compiled if the code is built without JrDebugLog support.
|