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