TestFailure

   
TestFailure

Description

The class TestFailure (see Figure C-22) summarizes the failure of a Test . The failure may be due to an assertion failure or an error. An error is defined as any exception that isn't an assertion failure.

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

Figure C-22. The class TestFailure
figs/utf_ac22.gif

Declaration

 class TestFailure 

Constructors/Destructors


TestFailure(Test *failedTest, Exception *thrownException, bool isError)

A constructor taking the Test that failed, the Exception that was thrown, and a flag indicating whether the failure was an assertion failure or an error.


virtual ~TestFailure( )

A destructor.

Public Methods


virtual TestFailure *clone( ) const

Returns a copy of this TestFailure .


virtual Test *failedTest( ) const

Returns the failed Test .


virtual string failedTestName( ) const

Returns the name of the failed Test .


virtual bool isError( ) const

Returns TRUE if the TestFailure is due to an error and not to an assertion failure.


virtual SourceLine sourceLine( ) const

Returns the SourceLine for this TestFailure .


virtual Exception *thrownException( ) const

Returns the Exception associated with this TestFailure .


virtual string toString( ) const

Returns a string representation of this TestFailure .

Protected/Private Methods


TestFailure(const TestFailure &other)

A copy constructor declared private to prevent its use.


TestFailure& operator=(const TestFailure& other)

A copy operator declared private to prevent its use.

Attributes


Test *m_failedTest

The failed Test ( protected ).


bool m_isError

Returns TRUE if the TestFailure is due to an error, FALSE if it is due to an assertion failure ( protected ).


Exception *m_thrownException

The Exception associated with this TestFailure ( protected ).

   
TestFixture

Description

The class TestFixture (see Figure C-23) defines the interface of a test fixture. TestCase is descended from TestFixture , so every test object is implicitly a test fixture. However, a test object is truly being used as a fixture only if it has multiple test methods that share objects. Philosophically, a fixture is a test environment, and the test methods interact with the environment to test different behaviors.

The TestFixture methods setUp() and tearDown( ) are used to initialize and clean up the fixture's shared objects. When there are multiple test methods in the fixture, setUp() and tearDown( ) are called for each one. This ensures test isolation by making sure the fixture is in the same state for each test.

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

Figure C-23. The class TestFixture
figs/utf_ac23.gif

Declaration

 class TestFixture 

Constructors/Destructors


virtual ~TestFixture( )

A destructor.

Public Methods


virtual void setUp( ) {}

Initializes the fixture's shared objects. The default implementation does nothing.


virtual void tearDown( ) {}

Cleans up the fixture's shared objects. The default implementation does nothing.

Protected/Private Methods

None.

Attributes

None.

   
TestFixtureFactory

Description

The abstract class TestFixtureFactory (see Figure C-24) defines the interface for a factory to produce TestFixture objects.

TestFixtureFactory belongs to the namespace CppUnit . It is declared in extensions/HelperMacros.h . It is abstract and has no implementation.

Figure C-24. The abstract class TestFixtureFactory
figs/utf_ac24.gif

Declaration

 class TestFixtureFactory 

Constructors/Destructors

None.

Public Methods


virtual TestFixture *makeFixture( ) = 0

A pure virtual method to create a TestFixture .

Protected/Private Methods

None.

Attributes

None.