CppUnit project page FAQ

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TestCaller< Fixture > Class Template Reference

Generate a test case from a fixture method. More...

#include <TestCaller.h>

Inheritance diagram for TestCaller< Fixture >:
Inheritance graph
[legend]
Collaboration diagram for TestCaller< Fixture >:
Collaboration graph
[legend]

Public Member Functions

 TestCaller (std::string name, TestMethod test)
 
 TestCaller (std::string name, TestMethod test, Fixture &fixture)
 
 TestCaller (std::string name, TestMethod test, Fixture *fixture)
 
 TestCaller (std::string name, std::function< void()> test_function, Fixture *fixture)
 
 ~TestCaller ()
 
void runTest ()
 FIXME: this should probably be pure virtual. More...
 
void setUp ()
 Set up context before running a test. More...
 
void tearDown ()
 Clean up after the test run. More...
 
std::string toString () const
 
- Public Member Functions inherited from TestCase
 TestCase (const std::string &name)
 Constructs a test case. More...
 
 TestCase ()
 Constructs a test case for a suite. More...
 
 ~TestCase ()
 Destructs a test case. More...
 
virtual void run (TestResult *result)
 Run the test and catch any exceptions that are triggered by it. More...
 
std::string getName () const
 Returns the name of the test case. More...
 
- Public Member Functions inherited from TestLeaf
int countTestCases () const
 
int getChildTestCount () const
 
TestdoGetChildTestAt (int index) const
 
- Public Member Functions inherited from Test
virtual ~Test ()
 
virtual TestgetChildTestAt (int index) const
 Returns the child test of the specified index. More...
 
virtual bool findTestPath (const std::string &testName, TestPath &testPath) const
 Finds the test with the specified name and its parents test. More...
 
virtual bool findTestPath (const Test *test, TestPath &testPath) const
 Finds the specified test and its parents test. More...
 
virtual TestfindTest (const std::string &testName) const
 Finds the test with the specified name in the hierarchy. More...
 
virtual TestPath resolveTestPath (const std::string &testPath) const
 Resolved the specified test path with this test acting as 'root'. More...
 
- Public Member Functions inherited from TestFixture
virtual ~TestFixture ()
 

Private Types

typedef void(Fixture::* TestMethod) ()
 

Private Member Functions

 TestCaller (const TestCaller &other)
 
TestCalleroperator= (const TestCaller &other)
 

Private Attributes

bool m_ownFixture
 
Fixture * m_fixture
 
std::function< void()> m_test_function
 

Additional Inherited Members

- Protected Member Functions inherited from Test
virtual void checkIsValidIndex (int index) const
 

Detailed Description

template<class Fixture>
class TestCaller< Fixture >

Generate a test case from a fixture method.

A test caller provides access to a test case method on a test fixture class. Test callers are useful when you want to run an individual test or add it to a suite. Test Callers invoke only one Test (i.e. test method) on one Fixture of a TestFixture.

Here is an example:

class MathTest : public CppUnit::TestFixture {
...
public:
void setUp();
void tearDown();
void testAdd();
void testSubtract();
};
CppUnit::Test *MathTest::suite() {
CppUnit::TestSuite *suite = new CppUnit::TestSuite;
suite->addTest( new CppUnit::TestCaller<MathTest>( "testAdd", testAdd ) );
return suite;
}
void tearDown()
Clean up after the test run.
Definition: TestCaller.h:183
void setUp()
Set up context before running a test.
Definition: TestCaller.h:178

You can use a TestCaller to bind any test method on a TestFixture class, as long as it accepts void and returns void.

See also
TestCase

Member Typedef Documentation

◆ TestMethod

template<class Fixture >
typedef void(Fixture::* TestCaller< Fixture >::TestMethod) ()
private

Constructor & Destructor Documentation

◆ TestCaller() [1/5]

template<class Fixture >
TestCaller< Fixture >::TestCaller ( std::string  name,
TestMethod  test 
)
inline

Constructor for TestCaller. This constructor builds a new Fixture instance owned by the TestCaller.

Parameters
namename of this TestCaller
testthe method this TestCaller calls in runTest()

◆ TestCaller() [2/5]

template<class Fixture >
TestCaller< Fixture >::TestCaller ( std::string  name,
TestMethod  test,
Fixture &  fixture 
)
inline

Constructor for TestCaller. This constructor does not create a new Fixture instance but accepts an existing one as parameter. The TestCaller will not own the Fixture object.

Parameters
namename of this TestCaller
testthe method this TestCaller calls in runTest()
fixturethe Fixture to invoke the test method on.

◆ TestCaller() [3/5]

template<class Fixture >
TestCaller< Fixture >::TestCaller ( std::string  name,
TestMethod  test,
Fixture *  fixture 
)
inline

Constructor for TestCaller. This constructor does not create a new Fixture instance but accepts an existing one as parameter. The TestCaller will own the Fixture object and delete it in its destructor.

Parameters
namename of this TestCaller
testthe method this TestCaller calls in runTest()
fixturethe Fixture to invoke the test method on.

◆ TestCaller() [4/5]

template<class Fixture >
TestCaller< Fixture >::TestCaller ( std::string  name,
std::function< void()>  test_function,
Fixture *  fixture 
)
inline

◆ ~TestCaller()

template<class Fixture >
TestCaller< Fixture >::~TestCaller ( )
inline

◆ TestCaller() [5/5]

template<class Fixture >
TestCaller< Fixture >::TestCaller ( const TestCaller< Fixture > &  other)
private

Member Function Documentation

◆ operator=()

template<class Fixture >
TestCaller& TestCaller< Fixture >::operator= ( const TestCaller< Fixture > &  other)
private

◆ runTest()

template<class Fixture >
void TestCaller< Fixture >::runTest ( )
inlinevirtual

FIXME: this should probably be pure virtual.

All the work for runTest is deferred to subclasses.

Reimplemented from TestCase.

◆ setUp()

template<class Fixture >
void TestCaller< Fixture >::setUp ( )
inlinevirtual

Set up context before running a test.

Reimplemented from TestFixture.

◆ tearDown()

template<class Fixture >
void TestCaller< Fixture >::tearDown ( )
inlinevirtual

Clean up after the test run.

Reimplemented from TestFixture.

◆ toString()

template<class Fixture >
std::string TestCaller< Fixture >::toString ( ) const
inline

Member Data Documentation

◆ m_fixture

template<class Fixture >
Fixture* TestCaller< Fixture >::m_fixture
private

◆ m_ownFixture

template<class Fixture >
bool TestCaller< Fixture >::m_ownFixture
private

◆ m_test_function

template<class Fixture >
std::function<void()> TestCaller< Fixture >::m_test_function
private

The documentation for this class was generated from the following file:

Send comments to:
CppUnit Developers