The class TestRunner (see Figure C-28) provides the user interface to run tests and output the results. CppUnit includes three versions of TestRunner : a text version, a Qt GUI version, and an MFC GUI version. The text version is summarized here, since it is the most generic. The usage of the other two versions is similar.
The code sample below demonstrates using TestRunner to run BookTest and print the results. A TestSuite containing multiple Test objects can be run the same way.
TestRunner runner; runner.addTest( BookTest ); runner.run( );
The text TestRunner belongs to the namespace CppUnit::TextUi . It is declared in the file ui/text/TestRunner.h and implemented in the file TestRunner.cpp .
Constructs a TestRunner . If no Outputter is provided, a TextOutputter that prints to stdout is created.
Adds a Test to this TestRunner . Multiple Test objects may be added.
Returns the TestResult for this TestRunner . Additional TestListener objects can be added to the TestResult to obtain test progress and results notifications.
Returns the TestResultCollector containing the results of the Test objects that were run.
Runs the Test specified by testName . If no testName is given, runs all the added Test objects. If doWait is TRUE , the user must press Return to start the run. If doPrintResult is TRUE , the test result summary is printed. If doPrintProgress is TRUE , a progress indicator is printed as the tests are run.
Sets the Outputter object. Allows a custom Outputter to be used to output test results. The default Outputter is a TextOutputter .
A protected method returning the Test with the given name, or NULL if it is not found.
A protected method that calls the Outputter 's write( ) method if doPrintResult is TRUE .
A protected method that runs a Test . If doPrintProgress is TRUE , a TextTestProgressListener is used to print a progress indicator.
A protected method that calls findTestByName( ) to get the named Test and calls runTest( ) to run to run the named Test .
A pprotected method that waits for user input if doWait is TRUE .
The TestResult that receives the results of Test objects run by this TestRunner ( protected ).
The Outputter that outputs test results for this TestRunner ( protected ).
The TestResultCollector where the test results for this TestRunner are stored ( protected ).
The TestSuite to which addTest() adds Test objects ( protected ).