This unit testing structure is based loosely on the ideas of CppUnitLite by Michael Feathers. However, it is a complete re-write and he has no responsibility for it. It also incorporates ideas from other implementations, notably that of producing HTML output using CSS for highlighting.
XUnitTest is a light-weight framework for making unit testing easier. For more information about unit testing and test driven development see for instance http://en.wikipedia.org/wiki/Unit_test and http://en.wikipedia.org/wiki/Test-driven_development
The structure of a unit test is basically very simple. The tests are written using the TEST() macro to start each test, followed by a block of code which may contain one or more CHECK() macros. These macros evaluate their argument to produce a true or false result, and call either a success() or a failure() method as a consequence to output or store the result of each check. Note that unlike some systems failing a check does not result in termination of a test, it continues with that and any other tests.
For example, a simple unit test file t.cpp might be something like:
#include <xunittest/test.h> TEST(group, test1) { int i = 1; int j = 2; CHECK(i == j-1); } TEST(group, test2) { int i = 1; int j = 1; CHECK(i == j); } int main(int argc, char **argv) { XUnitTest::doOptions(argc, argv); return 0; }
Output from this would by default be the text:
TEST group.test1 SUCCESS t.cpp:7 'i == j-1' TEST group.test2 SUCCESS t.cpp:14 'i == j' ALL TESTS PASSED: 2 RAN
For other output options see running the test.
1.5.7.1