Menu

[r242]: / trunk / cppunit / include / cppunit / ui / text / TestRunner.h  Maximize  Restore  History

Download this file

104 lines (85 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#ifndef CPPUNITUI_TEXT_TESTRUNNER_H
#define CPPUNITUI_TEXT_TESTRUNNER_H
#include <cppunit/Portability.h>
#include <string>
#include <vector>
namespace CppUnit {
class Outputter;
class Test;
class TestSuite;
class TextOutputter;
class TestResult;
class TestResultCollector;
namespace TextUi
{
/*!
* \brief A text mode test runner.
* \ingroup WritingTestResult
* \ingroup ExecutingTest
*
* The test runner manage the life cycle of the added tests.
*
* The test runner can run only one of the added tests or all the tests.
*
* TestRunner prints out a trace as the tests are executed followed by a
* summary at the end. The trace and summary print are optional.
*
* Here is an example of use:
*
* \code
* CppUnit::TextUi::TestRunner runner;
* runner.addTest( ExampleTestCase::suite() );
* runner.run( "", true ); // Run all tests and wait
* \endcode
*
* The trace is printed using a TextTestProgressListener. The summary is printed
* using a TextOutputter.
*
* You can specify an alternate Outputter at construction
* or later with setOutputter().
*
* After construction, you can register additional TestListener to eventManager(),
* for a custom progress trace, for example.
*
* \code
* CppUnit::TextUi::TestRunner runner;
* runner.addTest( ExampleTestCase::suite() );
* runner.setOutputter( CppUnit::CompilerOutputter::defaultOutputter(
* &runner.result(),
* std::cerr ) );
* MyCustomProgressTestListener progress;
* runner.eventManager().addListener( &progress );
* runner.run( "", true ); // Run all tests and wait
* \endcode
*
* \see CompilerOutputter, XmlOutputter, TextOutputter.
*/
class CPPUNIT_API TestRunner
{
public:
TestRunner( Outputter *outputter =NULL );
virtual ~TestRunner();
bool run( std::string testName ="",
bool doWait = false,
bool doPrintResult = true,
bool doPrintProgress = true );
void addTest( Test *test );
void setOutputter( Outputter *outputter );
TestResultCollector &result() const;
TestResult &eventManager() const;
protected:
virtual bool runTest( Test *test,
bool doPrintProgress );
virtual bool runTestByName( std::string testName,
bool printProgress );
virtual void wait( bool doWait );
virtual void printResult( bool doPrintResult );
virtual Test *findTestByName( std::string name ) const;
TestSuite *m_suite;
TestResultCollector *m_result;
TestResult *m_eventManager;
Outputter *m_outputter;
};
} // namespace TextUi
} // namespace CppUnit
#endif // CPPUNITUI_TEXT_TESTRUNNER_H
MongoDB Logo MongoDB