CppUnit project page | FAQ | CppUnit home page |
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. More...
#include <TestCaller.h>
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 () | |
void | runTest () |
FIXME: this should probably be pure virtual. | |
void | setUp () |
Set up context before running a test. | |
void | tearDown () |
Clean up after the test run. | |
std::string | toString () const |
Private Types | |
typedef void(Fixture::* | TestMethod )() |
Private Member Functions | |
TestCaller (const TestCaller &other) | |
TestCaller & | operator= (const TestCaller &other) |
Private Attributes | |
bool | m_ownFixture |
Fixture * | m_fixture |
TestMethod | m_test |
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; }
You can use a TestCaller to bind any test method on a TestFixture class, as long as it accepts void and returns void.
typedef void(Fixture::* TestCaller< Fixture >::TestMethod)() [private] |
TestCaller< Fixture >::TestCaller | ( | std::string | name, |
TestMethod | test | ||
) | [inline] |
Constructor for TestCaller. This constructor builds a new Fixture instance owned by the TestCaller.
name | name of this TestCaller |
test | the method this TestCaller calls in runTest() |
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.
name | name of this TestCaller |
test | the method this TestCaller calls in runTest() |
fixture | the Fixture to invoke the test method on. |
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.
name | name of this TestCaller |
test | the method this TestCaller calls in runTest() |
fixture | the Fixture to invoke the test method on. |
TestCaller< Fixture >::~TestCaller | ( | ) | [inline] |
TestCaller< Fixture >::TestCaller | ( | const TestCaller< Fixture > & | other | ) | [private] |
TestCaller& TestCaller< Fixture >::operator= | ( | const TestCaller< Fixture > & | other | ) | [private] |
void TestCaller< Fixture >::runTest | ( | ) | [inline, virtual] |
FIXME: this should probably be pure virtual.
All the work for runTest is deferred to subclasses.
Reimplemented from TestCase.
void TestCaller< Fixture >::setUp | ( | ) | [inline, virtual] |
Set up context before running a test.
Reimplemented from TestFixture.
void TestCaller< Fixture >::tearDown | ( | ) | [inline, virtual] |
Clean up after the test run.
Reimplemented from TestFixture.
std::string TestCaller< Fixture >::toString | ( | ) | const [inline] |
Fixture* TestCaller< Fixture >::m_fixture [private] |
bool TestCaller< Fixture >::m_ownFixture [private] |
TestMethod TestCaller< Fixture >::m_test [private] |
|
hosts this site. |
Send comments to: CppUnit Developers |