TestResult

   
TestResult

Description

The class TestResult (see Figure C-26) receives test results from Test objects. Test results can be categorized as successes, failures, and errors. Normally, when multiple Test classes are run, a single TestResult is passed to the run( ) method of each Test .

A TestResult informs its observers of test progress and results using the TestListener interface. The TestListener subclass TestResultCollector normally is used to store the results. TestResult doesn't store the results itself.

A TestResult is a SynchronizedObject . Its operations are mutex-protected and thread-safe, allowing Test and TestListener objects to run in separate threads.

TestResult belongs to the namespace CppUnit . It is declared in TestResult.h and implemented in TestResult.cpp .

Figure C-26. The class TestResult
figs/utf_ac26.gif

Declaration

 class TestResult : protected SynchronizedObject 

Constructors/Destructors


TestResult(SynchronizationObject *syncObject = 0)

A constructor. If a SynchronizationObject is not provided, a new one is created.


virtual ~TestResult( )

A destructor.


Public Methods

virtual void addError(Test *test, Exception *e)

A method that informs TestResult of a test error (an Exception not caused by a test assertion).


virtual void addFailure(Test *test, Exception *e)

A method that informs TestResult of a test failure (an Exception caused by a test assertion).


virtual void addListener(TestListener *listener)

Adds a TestListener to this TestResult .


virtual void endTest(Test *test)

A method that informs TestResult that test has ended.


virtual void removeListener(TestListener *listener)

Removes a TestListener from this TestResult .


virtual void reset( )

Sets m_stop to FALSE to prepare for a new test run.


virtual bool shouldStop( ) const

Returns the value of m_stop .


virtual void startTest(Test *test)

A method that informs TestResult that test is about to be run.


virtual void stop( )

Sets m_stop to TRUE to stop the test run.

Protected/Private Methods


void addFailure(const TestFailure &failure)

A protected method that adds a TestFailure and inform listeners.


TestResult(const TestResult &other)

A copy constructor declared private to prevent its use.


TestResult& operator=(const TestResult &other)

A copy operator declared private to prevent its use.

Attributes


typedef deque<TestListener *> TestListeners

Defines the type TestListeners as a deque of TestListener objects ( protected ).


TestListeners m_listeners

The test listeners ( protected ).


bool m_stop

If TRUE , the test run should stop ( protected ).



Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net