TestSuiteBuilder

   
TestSuiteBuilder

Description

The template class TestSuiteBuilder (see Figure C-32) is a helper class used to add tests to a TestSuite . It is used by the macros CPPUNIT_TEST_SUITE( ) and CPPUNIT_TEST_SUITE_END( ) .

TestSuiteBuilder belongs to the namespace CppUnit . It is declared and implemented in the file extensions/TestSuiteBuilder.h .

Figure C-32. The template class TestSuiteBuilder
figs/utf_ac32.gif

Declaration

 template<typename Fixture> class TestSuiteBuilder 

Constructors/Destructors


TestSuiteBuilder(TestSuite *suite)

Constructs a TestSuiteBuilder for a TestSuite .


TestSuiteBuilder(string name )

Constructs a TestSuiteBuilder and a new TestSuite with the given name.

Public Methods


void addTest(Test *test)

Adds test to the TestSuite .


void addTestCaller(string methodName, TestMethod testMethod)

Adds a TestCaller that calls the TestMethod .


void addTestCaller(string methodName, TestMethod testMethod, Fixture *fixture)

Adds a TestCaller that calls the TestMethod in the context of the Fixture .


template<typename ExceptionType>

void addTestCallerForException(string methodName, TestMethod testMethod, Fixture *fixture, ExceptionType *dummyPointer)

A template function to add a TestCaller that calls the TestMethod in the context of the Fixture . The TestMethod is expected to throw an Exception of type ExceptionType .


string makeTestName(const string &methodName)

Returns a test name that incorporates the TestSuite name and methodName .


TestSuite *suite( ) const

Returns the TestSuite for this TestSuiteBuilder .


TestSuite *takeSuite( )

Takes ownership of the TestSuite from the smart pointer m_suite .

Protected/Private Methods


TestSuite(const TestSuite &other)

A copy constructor declared private to prevent its use.


TestSuite& operator=(const TestSuite &other)

A copy operator declared private to prevent its use.

Attributes


std::auto_ptr<TestSuite> m_suite

A smart pointer to the TestSuite for this TestSuiteBuilder ( private ).

   
TestSuiteFactory

Description

The template class TestSuiteFactory (see Figure C-33) implements the TestFactory method makeTest( ) for a TestFixture having a static suite( ) method. TestSuiteFactory is used by the class AutoRegisterSuite .

TestSuiteFactory belongs to the namespace CppUnit . It is declared and implemented in the file extensions/TestSuiteFactory.h .

Figure C-33. The template class TestSuiteFactory
figs/utf_ac33.gif

Declaration

 template<typename TestCaseType>

   class TestSuiteFactory : public TestFactory 

Constructors/Destructors

None.

Public Methods


virtual Test *makeTest( )

Calls the method TestCaseType::suite( ) to return a TestSuite .

Protected/Private Methods

None.

Attributes

None.

   
TextOutputter

Description

The class TextOutputter (see Figure C-34) is a subclass of Outputter . It gets test results from a TestResultCollector and outputs them in text format to an output stream.

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

Figure C-34. The class TextOutputter
figs/utf_ac34.gif

Declaration

 class TextOutputter : public Outputter 

Constructors/Destructors


TextOutputter(TestResultCollector *result, ostream & stream)

Creates a TextOutputter to get test results from result and output them to stream .


virtual ~TextOutputter( )

A destructor.

Public Methods


virtual void printFailure(TestFailure *failure, int failureNumber)

virtual void printFailureDetail(Exception *thrownException)

virtual void printFailureListMark(int failureNumber)

virtual void printFailureLocation(SourceLine sourceLine)

virtual void printFailures( )

virtual void printFailureTestName(TestFailure *failure)

virtual void printFailureType(TestFailure *failure)

virtual void printFailureWarning( )

virtual void printHeader( )

virtual void printStatistics( )

Methods that print various portions of the test results to m_stream . Generally, the write() method is called instead of calling these methods directly.


void write( )

A method called to output results. Calls printHeader() and printFailures( ) .

Protected/Private Methods


TextOutputter(const TextOutputter& copy)

A copy constructor, scoped private to prevent its use.


void operator=(const TextOutputter& copy)

A copy operator, scoped private to prevent its use.

Attributes


TestResultCollector *m_result

The TestResultCollector passed in the constructor. ( private )


ostream& m_stream

The output stream passed in the constructor. ( private )