TextTestRunner.h 2.5 KB

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