1 #ifndef CPPUNIT_TESTRUNNER_H
2 #define CPPUNIT_TESTRUNNER_H
4 #include <cppunit/TestSuite.h>
14 /*! \brief Generic test runner.
15 * \ingroup ExecutingTest
17 * The TestRunner assumes ownership of all added tests: you can not add test
18 * or suite that are local variable since they can't be deleted.
22 * #include <cppunit/extensions/TestFactoryRegistry.h>
23 * #include <cppunit/CompilerOutputter.h>
24 * #include <cppunit/TestResult.h>
25 * #include <cppunit/TestResultCollector.h>
26 * #include <cppunit/TestRunner.h>
27 * #include <cppunit/TextTestProgressListener.h>
31 * main( int argc, char* argv[] )
33 * std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
35 * // Create the event manager and test controller
36 * CppUnit::TestResult controller;
38 * // Add a listener that colllects test result
39 * CppUnit::TestResultCollector result;
40 * controller.addListener( &result );
42 * // Add a listener that print dots as test run.
43 * CppUnit::TextTestProgressListener progress;
44 * controller.addListener( &progress );
46 * // Add the top suite to the test runner
47 * CppUnit::TestRunner runner;
48 * runner.addTest( CppUnit::TestFactoryRegistry::getRegistry().makeTest() );
51 * std::cout << "Running " << testPath;
52 * runner.run( controller, testPath );
54 * std::cerr << std::endl;
56 * // Print test in a compiler compatible format.
57 * CppUnit::CompilerOutputter outputter( &result, std::cerr );
60 * catch ( std::invalid_argument &e ) // Test path not resolved
62 * std::cerr << std::endl
63 * << "ERROR: " << e.what()
68 * return result.wasSuccessful() ? 0 : 1;
72 class CPPUNIT_API TestRunner
75 /*! \brief Constructs a TestRunner object.
80 virtual ~TestRunner();
82 /*! \brief Adds the specified test.
83 * \param test Test to add. The TestRunner takes ownership of the test.
85 virtual void addTest( Test *test );
87 /*! \brief Runs a test using the specified controller.
88 * \param controller Event manager and controller used for testing
89 * \param testPath Test path string. See Test::resolveTestPath() for detail.
90 * \exception std::invalid_argument if no test matching \a testPath is found.
91 * see TestPath::TestPath( Test*, const std::string &)
94 virtual void run( TestResult &controller,
95 const std::string &testPath = "" );
98 /*! \brief (INTERNAL) Mutating test suite.
100 class CPPUNIT_API WrappingSuite : public TestSuite
103 WrappingSuite( const std::string &name = "All Tests" );
105 int getChildTestCount() const;
107 std::string getName() const;
109 void run( TestResult *result );
112 Test *doGetChildTestAt( int index ) const;
114 bool hasOnlyOneTest() const;
116 Test *getUniqueChildTest() const;
120 WrappingSuite *m_suite;
123 /// Prevents the use of the copy constructor.
124 TestRunner( const TestRunner © );
126 /// Prevents the use of the copy operator.
127 void operator =( const TestRunner © );
135 #endif // CPPUNIT_TESTRUNNER_H