CppUnit project page | FAQ | CppUnit home page |
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <cppunit/extensions/AutoRegisterSuite.h>
#include <cppunit/extensions/ExceptionTestCaseDecorator.h>
#include <cppunit/extensions/TestFixtureFactory.h>
#include <cppunit/extensions/TestNamer.h>
#include <cppunit/extensions/TestSuiteBuilderContext.h>
#include <memory>
Go to the source code of this file.
Defines | |
#define | CPPUNIT_TEST_SUITE(ATestFixtureType) |
Begin test suite. | |
#define | CPPUNIT_TEST_SUB_SUITE(ATestFixtureType, ASuperClass) |
Begin test suite (includes parent suite). | |
#define | CPPUNIT_TEST_SUITE_END() |
End declaration of the test suite. | |
#define | CPPUNIT_TEST_SUITE_END_ABSTRACT() |
End declaration of an abstract test suite. | |
#define | CPPUNIT_TEST_SUITE_ADD_TEST(test) context.addTest( test ) |
Add a test to the suite (for custom test macro). | |
#define | CPPUNIT_TEST(testMethod) |
Add a method to the suite. | |
#define | CPPUNIT_TEST_EXCEPTION(testMethod, ExceptionType) |
Add a test which fail if the specified exception is not caught. | |
#define | CPPUNIT_TEST_FAIL(testMethod) CPPUNIT_TEST_EXCEPTION( testMethod, CPPUNIT_NS::Exception ) |
Adds a test case which is excepted to fail. | |
#define | CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS(testAdderMethod) testAdderMethod( context ) |
Adds some custom test cases. | |
#define | CPPUNIT_TEST_SUITE_PROPERTY(APropertyKey, APropertyValue) |
Adds a property to the test suite builder context. | |
#define | CPPUNIT_TEST_SUITE_REGISTRATION(ATestFixtureType) |
#define | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ATestFixtureType, suiteName) |
Adds the specified fixture suite to the specified registry suite. | |
#define | CPPUNIT_REGISTRY_ADD(which, to) |
#define | CPPUNIT_REGISTRY_ADD_TO_DEFAULT(which) |
The macros CPPUNIT_TEST_SUITE(), CPPUNIT_TEST(), and CPPUNIT_TEST_SUITE_END() are designed to facilitate easy creation of a test suite. For example,
#include <cppunit/extensions/HelperMacros.h> class MyTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( MyTest ); CPPUNIT_TEST( testEquality ); CPPUNIT_TEST( testSetName ); CPPUNIT_TEST_SUITE_END(); public: void testEquality(); void testSetName(); };
The effect of these macros is to define two methods in the class MyTest. The first method is an auxiliary function named registerTests that you will not need to call directly. The second function
returns a pointer to the suite of tests defined by the CPPUNIT_TEST() macros.static CppUnit::TestSuite *suite()
Rather than invoking suite() directly, the macro CPPUNIT_TEST_SUITE_REGISTRATION() is used to create a static variable that automatically registers its test suite in a global registry. The registry yields a Test instance containing all the registered suites.
CPPUNIT_TEST_SUITE_REGISTRATION( MyTest ); CppUnit::Test* tp = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
The test suite macros can even be used with templated test classes. For example:
template<typename CharType> class StringTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( StringTest ); CPPUNIT_TEST( testAppend ); CPPUNIT_TEST_SUITE_END(); public: ... };
You need to add in an implementation file:
CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<char> ); CPPUNIT_TEST_SUITE_REGISTRATION( StringTest<wchar_t> );
hosts this site. |
Send comments to: CppUnit Developers |