Name

TestRunner

Description

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.

The text version of TestRunner
Figure C-28. The text version of TestRunner

Declaration

class TestRunner

Constructors/Destructors

TestRunner(Outputter *outputter = NULL)

Constructs a TestRunner. If no Outputter is provided, a TextOutputter that prints to stdout is created.

virtual ~TestRunner( )

A destructor.

Public Methods

void addTest(Test *test)

Adds a Test to this TestRunner. Multiple Test objects may be added.

TestResult &eventManager( ) const

Returns the TestResult for this TestRunner. Additional TestListener objects can be added to the TestResult to obtain test progress and results notifications.

TestResultCollector &result( ) const

Returns the TestResultCollector containing the results of the Test ...

Get Unit Test Frameworks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.