| CppUnit project page | FAQ | CppUnit home page |
Files | |
| file | HelperMacros.h |
| Macros intended to ease the definition of test suites. | |
Compounds | |
| class | CppUnit::TestCaller |
| Generate a test case from a fixture method. More... | |
| class | CppUnit::TestFixture |
| Wraps a test case with setUp and tearDown methods. More... | |
| class | CppUnit::TestSuiteBuilder |
| Helper to add tests to a TestSuite. More... | |
Defines | |
| #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(testMethod) |
| Add a method to the suite. More... | |
| #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::Exception ) |
| Adds a test case which is excepted to fail. More... | |
| #define | CPPUNIT_TEST_SUITE_END() |
| End declaration of the test suite. More... | |
|
|
Value: builder.addTestCaller( #testMethod, \
&__ThisTestFixtureType::testMethod , \
(__ThisTestFixtureType*)factory->makeFixture() )
|
|
|
Value: builder.addTestCallerForException( #testMethod, \
&__ThisTestFixtureType::testMethod , \
(__ThisTestFixtureType*)factory->makeFixture(), \
(ExceptionType *)NULL );Example: #include <cppunit/extensions/HelperMacros.h> #include <vector> class MyTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( MyTest ); CPPUNIT_TEST_EXCEPTION( testVectorAtThrow, std::invalid_argument ); CPPUNIT_TEST_SUITE_END(); public: void testVectorAtThrow() { std::vector<int> v; v.at( 1 ); // must throw exception std::invalid_argument } };
|
|
|
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.
CPPUNIT_TEST_FAIL( testAssertFalseFail ); void testAssertFalseFail() { CPPUNIT_ASSERT( false ); }
|
|
|
Value: private: \
typedef ASuperClass __ThisSuperClassType; \
CPPUNIT_TEST_SUITE( ATestFixtureType ); \
__ThisSuperClassType::registerTests( suite, factory )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:
#include <cppunit/extensions/HelperMacros.h> class MySubTest : public MyTest { CPPUNIT_TEST_SUB_SUITE( MySubTest, MyTest ); CPPUNIT_TEST( testAdd ); CPPUNIT_TEST( testSub ); CPPUNIT_TEST_SUITE_END(); public: void testAdd(); void testSub(); };
|
|
|
Value: private: \
typedef ATestFixtureType __ThisTestFixtureType; \
class ThisTestFixtureFactory : public CppUnit::TestFixtureFactory \
{ \
virtual CppUnit::TestFixture *makeFixture() \
{ \
return new ATestFixtureType(); \
} \
}; \
public: \
static void \
registerTests( CppUnit::TestSuite *suite, \
CppUnit::TestFixtureFactory *factory ) \
{ \
CppUnit::TestSuiteBuilder<__ThisTestFixtureType> builder( 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.
|
|
|
Value: builder.takeSuite(); \
} \
static CppUnit::TestSuite *suite() \
{ \
CppUnit::TestSuiteBuilder<__ThisTestFixtureType> \
builder __CPPUNIT_SUITE_CTOR_ARGS( ATestFixtureType ); \
ThisTestFixtureFactory factory; \
__ThisTestFixtureType::registerTests( builder.suite(), &factory ); \
return builder.takeSuite(); \
} \
private: \
typedef ThisTestFixtureFactory __ThisTestFixtureFactoryAfter this macro, member access is set to "private".
|
|
|
hosts this site. |
Send comments to: CppUnit Developers |