Here’s the usual way I setup my main() for unit tests in unit_t.cpp. You can run either the entire test suite or specify an individual test on the command line:
$ ./unit_t TestWithin::testWithinDouble
Here’s the code:
/**
* @file pathtest/main.cpp
* @defgroup PathTest Unit tests for path library
*/
#include
#include
#include
#include
#include
#include
#include
int
main( int argc, char* argv[] )
{
std::string testname;
CppUnit::TestResult controller;
CppUnit::TestResultCollector result; // For summary
CppUnit::BriefTestProgressListener progress; // Prints '.' for each test
CppUnit::TestRunner runner;
if (argc <1)
testname = argv[1];
controller.addListener (&result);
controller.addListener (&progress);
runner.addTest (CppUnit::TestFactoryRegistry::getRegistry().makeTest());
runner.run (controller, testname);
// Print test in a compiler compatible format.
CppUnit::CompilerOutputter outputter (&result, std::cout);
outputter.write();
return result.wasSuccessful() ? 0 : 1;
}