CppUnit project page | FAQ |
Files | |
file | HelperMacros.h |
Macros intended to ease the definition of test suites. | |
Classes | |
class | TestCaller< Fixture > |
Generate a test case from a fixture method. More... | |
class | TestFixture |
Wraps a test case with setUp and tearDown methods. More... | |
Macros | |
#define | CPPUNIT_TEST_SUITE(ATestFixtureType) |
Begin test suite. More... | |
#define | CPPUNIT_TEST_SUB_SUITE(ATestFixtureType, ASuperClass) |
Begin test suite (includes parent suite) More... | |
#define | CPPUNIT_TEST_SUITE_END() |
End declaration of the test suite. More... | |
#define | CPPUNIT_TEST_SUITE_END_ABSTRACT() |
End declaration of an abstract test suite. More... | |
#define | CPPUNIT_TEST_FIXTURE(TestClass, TestName) |
Define test suite with a single test. More... | |
#define | CPPUNIT_TEST_SUITE_ADD_TEST(test) context.addTest( test ) |
Add a test to the suite (for custom test macro). More... | |
#define | CPPUNIT_TEST(testMethod) |
Add a method to the suite. More... | |
#define | CPPUNIT_TEST_PARAMETERIZED(testMethod, ...) |
#define | CPPUNIT_TEST_EXCEPTION(testMethod, ExceptionType) |
Add a test which fail if the specified exception is not caught. More... | |
#define | CPPUNIT_TEST_FAIL(testMethod) CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception ) |
Adds a test case which is excepted to fail. More... | |
#define | CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS(testAdderMethod) testAdderMethod( context ) |
Adds some custom test cases. More... | |
#define | CPPUNIT_TEST_SUITE_PROPERTY(APropertyKey, APropertyValue) |
Adds a property to the test suite builder context. More... | |
#define CPPUNIT_TEST | ( | testMethod | ) |
Add a method to the suite.
testMethod | Name of the method of the test case to add to the suite. The signature of the method must be of type: void testMethod(); |
#define CPPUNIT_TEST_EXCEPTION | ( | testMethod, | |
ExceptionType | |||
) |
Add a test which fail if the specified exception is not caught.
Example:
testMethod | Name of the method of the test case to add to the suite. |
ExceptionType | Type of the exception that must be thrown by the test method. |
#define CPPUNIT_TEST_FAIL | ( | testMethod | ) | CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception ) |
Adds a test case which is excepted to fail.
The added test case expect an assertion to fail. You usually used that type of test case when testing custom assertion macros.
#define CPPUNIT_TEST_FIXTURE | ( | TestClass, | |
TestName | |||
) |
Define test suite with a single test.
This macro declares a new test suite with a single test and a single parent class. Use CPPUNIT_TEST_SUITE(), CPPUNIT_TEST() and CPPUNIT_TEST_SUITE_END() instead if you wish to include more tests in the suite. The benefit of using this macro is that you don't have to declare, register and define your test name manually, so you don't repeat yourself.
TestClass | Base class. This type MUST be derived from TestFixture. |
TestName | Name of the test. |
#define CPPUNIT_TEST_PARAMETERIZED | ( | testMethod, | |
... | |||
) |
#define CPPUNIT_TEST_SUB_SUITE | ( | ATestFixtureType, | |
ASuperClass | |||
) |
Begin test suite (includes parent suite)
This macro may only be used in a class whose parent class defines a test suite using CPPUNIT_TEST_SUITE() or CPPUNIT_TEST_SUB_SUITE().
This macro begins the declaration of a test suite, in the same manner as CPPUNIT_TEST_SUITE(). In addition, the test suite of the parent is automatically inserted in the test suite being defined.
Here is an example:
ATestFixtureType | Type of the test case class. This type MUST be derived from TestFixture. |
ASuperClass | Type of the parent class. |
#define CPPUNIT_TEST_SUITE | ( | ATestFixtureType | ) |
Begin test suite.
This macro starts the declaration of a new test suite. Use CPPUNIT_TEST_SUB_SUITE() instead, if you wish to include the test suite of the parent class.
ATestFixtureType | Type of the test case class. This type MUST be derived from TestFixture. |
#define CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS | ( | testAdderMethod | ) | testAdderMethod( context ) |
Adds some custom test cases.
Use this to add one or more test cases to the fixture suite. The specified method is called with a context parameter that can be used to name, instantiate fixture, and add instantiated test case to the fixture suite. The specified method must have the following signature:
TestSuiteBuilderContextType
is typedef to TestSuiteBuilderContext<TestFixtureType> declared by CPPUNIT_TEST_SUITE().
Here is an example that add two custom tests:
testAdderMethod | Name of the method called to add the test cases. |
#define CPPUNIT_TEST_SUITE_ADD_TEST | ( | test | ) | context.addTest( test ) |
Add a test to the suite (for custom test macro).
The specified test will be added to the test suite being declared. This macro is intended for advanced usage, to extend CppUnit by creating new macro such as CPPUNIT_TEST_EXCEPTION()...
Between macro CPPUNIT_TEST_SUITE() and CPPUNIT_TEST_SUITE_END(), you can assume that the following variables can be used:
context
can be used to name test case, create new test fixture instance, or add test case to the test fixture suite.
Below is an example that show how to use this macro to create new macro to add test to the fixture suite. The macro below show how you would add a new type of test case which fails if the execution last more than a given time limit. It relies on an imaginary TimeOutTestCaller class which has an interface similar to TestCaller.
test | Test to add to the suite. Must be a subclass of Test. The test name should have been obtained using TestNamer::getTestNameFor(). |
#define CPPUNIT_TEST_SUITE_END | ( | ) |
End declaration of the test suite.
After this macro, member access is set to "private".
#define CPPUNIT_TEST_SUITE_END_ABSTRACT | ( | ) |
End declaration of an abstract test suite.
Use this macro to indicate that the TestFixture is abstract. No static suite() method will be declared.
After this macro, member access is set to "private".
Here is an example of usage:
The abstract test fixture:
The concret test fixture:
#define CPPUNIT_TEST_SUITE_PROPERTY | ( | APropertyKey, | |
APropertyValue | |||
) |
Adds a property to the test suite builder context.
APropertyKey | Key of the property to add. |
APropertyValue | Value for the added property. Example: #define CPPUNIT_TEST_SUITE_PROPERTY(APropertyKey, APropertyValue) Adds a property to the test suite builder context. Definition: HelperMacros.h:447 |
Send comments to: CppUnit Developers |