The template class TestCaller (see Figure C-17) is used to create and run a TestCase containing a TestMethod , usually in the context of a TestFixture . This is useful when a TestFixture has multiple test methods but only one of them should be run, or when test methods are being run by name . A TestMethod must take no arguments and return void to be invoked using TestCaller .

When TestCaller is specialized and instantiated , the type Fixture should be TestFixture or a subclass of it. The type ExpectedException defaults to NoExceptionExpected , meaning that an Exception is not expected when the TestMethod is run, and the test fails if one is thrown. An Exception type can be provided when TestCaller is specialized, so that it is expected when the TestCase is run. In this case, the test fails if the ExpectedException is not thrown.

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

Figure C-17. The template class TestCaller


 template<typename Fixture, typename ExpectedException =  NoExceptionExpected>   class TestCaller : public TestCase 


TestCaller(string name, TestMethod test)

A constructor used when a TestFixture is not provided. In this case, the TestMethod is run in a new, default TestFixture owned by the TestCaller .

TestCaller(string name, TestMethod test, Fixture& fixture)

A constructor taking a TestMethod and a reference to a TestFixture . The TestCaller does not own the TestFixture in this case.

TestCaller(string name, TestMethod test, Fixture *fixture)

A constructor taking a TestMethod and a pointer to a TestFixture . When a TestCaller is constructed this way, it owns the TestFixture .

~TestCaller( )

A destructor. If the TestCaller owns the TestFixture , it deletes it.

Public Methods


Protected/Private Methods

void runTest( )

A Protected method that runs the TestMethod .

void setUp( )

A Protected method that sets up the Fixture by calling its setUp( ) method.

void tearDown( )

A Protected method that tears down the Fixture by calling its tearDown( ) method.

string toString( ) const

A Protected method returning a string representation of this TestCaller .

TestCaller(const TestCaller &other)

A copy constructor declared private to prevent its use.

TestCaller& operator=(const TestCaller &other)

A copy operator declared private to prevent its use.


Fixture *m_fixture

A pointer to Fixture ( private ).

bool m_ownFixture

If TRUE , TestCaller owns Fixture and deletes it in its destructor ( private ).

TestMethod m_test

The TestMethod that this TestCaller will run ( private ).

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