TestRunner

   
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 .

Figure C-28. The text version of TestRunner
figs/utf_ac28.gif

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 objects that were run.


bool run(string testName = "", bool doWait = false, bool doPrintResult = true, bool doPrintProgress = true)

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.


void setOutputter(Outputter *outputter)

Sets the Outputter object. Allows a custom Outputter to be used to output test results. The default Outputter is a TextOutputter .

Protected/Private Methods


virtual Test *findTestByName(string name ) const

A protected method returning the Test with the given name, or NULL if it is not found.


virtual void printResult(bool doPrintResult)

A protected method that calls the Outputter 's write( ) method if doPrintResult is TRUE .


virtual bool runTest(Test *test, bool doPrintProgress)

A protected method that runs a Test . If doPrintProgress is TRUE , a TextTestProgressListener is used to print a progress indicator.


virtual bool runTestByName(string testName, bool printProgress)

A protected method that calls findTestByName( ) to get the named Test and calls runTest( ) to run to run the named Test .


virtual void wait(bool doWait)

A pprotected method that waits for user input if doWait is TRUE .

Attributes


TestResult *m_eventManager

The TestResult that receives the results of Test objects run by this TestRunner ( protected ).


Outputter *m_outputter

The Outputter that outputs test results for this TestRunner ( protected ).


TestResultCollector *m_result

The TestResultCollector where the test results for this TestRunner are stored ( protected ).


TestSuite *m_suite

The TestSuite to which addTest() adds Test objects ( protected ).



Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net