1
#ifndef CPPUNIT_TESTLISTENER_H // -*- C++ -*-
2
#define CPPUNIT_TESTLISTENER_H
4
#include <cppunit/Portability.h>
16
/*! \brief Listener for test progress and result.
17
* \ingroup TrackingTestExecution
19
* Implementing the Observer pattern a TestListener may be registered
20
* to a TestResult to obtain information on the testing progress. Use
21
* specialized sub classes of TestListener for text output
22
* (TextTestProgressListener). Do not use the Listener for the test
23
* result output, use a subclass of Outputter instead.
25
* The test framework distinguishes between failures and errors.
26
* A failure is anticipated and checked for with assertions. Errors are
27
* unanticipated problems signified by exceptions that are not generated
30
* Here is an example to track test time:
34
* #include <cppunit/TestListener.h>
35
* #include <cppunit/Test.h>
36
* #include <time.h> // for clock()
38
* class TimingListener : public CppUnit::TestListener
41
* void startTest( CppUnit::Test *test )
43
* _chronometer.start();
46
* void endTest( CppUnit::Test *test )
49
* addTest( test, _chronometer.elapsedTime() );
52
* // ... (interface to add/read test timing result)
59
* And another example that track failure/success at test suite level and captures
60
* the TestPath of each suite:
62
* class SuiteTracker : public CppUnit::TestListener
65
* void startSuite( CppUnit::Test *suite )
67
* m_currentPath.add( suite );
70
* void addFailure( const TestFailure &failure )
72
* m_suiteFailure.top() = false;
75
* void endSuite( CppUnit::Test *suite )
77
* m_suiteStatus.insert( std::make_pair( suite, m_suiteFailure.top() ) );
78
* m_suitePaths.insert( std::make_pair( suite, m_currentPath ) );
81
* m_suiteFailure.pop();
85
* std::stack<bool> m_suiteFailure;
86
* CppUnit::TestPath m_currentPath;
87
* std::map<CppUnit::Test *, bool> m_suiteStatus;
88
* std::map<CppUnit::Test *, CppUnit::TestPath> m_suitePaths;
94
class CPPUNIT_API TestListener
97
virtual ~TestListener() {}
99
/// Called when just before a TestCase is run.
100
virtual void startTest( Test * /*test*/ ) {}
102
/*! \brief Called when a failure occurs while running a test.
104
* \warning \a failure is a temporary object that is destroyed after the
105
* method call. Use TestFailure::clone() to create a duplicate.
107
virtual void addFailure( const TestFailure & /*failure*/ ) {}
109
/// Called just after a TestCase was run (even if a failure occured).
110
virtual void endTest( Test * /*test*/ ) {}
112
/*! \brief Called by a TestComposite just before running its child tests.
114
virtual void startSuite( Test * /*suite*/ ) {}
116
/*! \brief Called by a TestComposite after running its child tests.
118
virtual void endSuite( Test * /*suite*/ ) {}
120
/*! \brief Called by a TestRunner before running the test.
122
* You can use this to do some global initialisation. A listener
123
* could also use to output a 'prolog' to the test run.
125
* \param test Test that is going to be run.
126
* \param eventManager Event manager used for the test run.
128
virtual void startTestRun( Test * /*test*/,
129
TestResult * /*eventManager*/ ) {}
131
/*! \brief Called by a TestRunner after running the test.
133
* TextTestProgressListener use this to emit a line break. You can also use this
134
* to do some global uninitialisation.
136
* \param test Test that was run.
137
* \param eventManager Event manager used for the test run.
139
virtual void endTestRun( Test * /*test*/,
140
TestResult * /*eventManager*/ ) {}
146
#endif // CPPUNIT_TESTLISTENER_H