CppUnit project page | FAQ

Classes | Macros
Creating TestSuite

## Classes

class | TestFactoryRegistry
| Registry for TestFactory.Notes that the registry DON'T assumes lifetime control for any registered tests anymore. More...
class | TestSuite
| A Composite of Tests.It runs a collection of test cases. Here is an example. More...

## Macros

#define | CPPUNIT_TEST_SUITE_REGISTRATION(ATestFixtureType)
#define | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(ATestFixtureType, suiteName)
| Adds the specified fixture suite to the specified registry suite. More...
#define | CPPUNIT_REGISTRY_ADD(which, to)
#define | CPPUNIT_REGISTRY_ADD_TO_DEFAULT(which)

## Detailed Description

## Macro Definition Documentation

## ◆ CPPUNIT_REGISTRY_ADD

#define CPPUNIT_REGISTRY_ADD | ( |  | which,
|  |  | to
| ) |  |

Value:
static CPPUNIT_NS::AutoRegisterRegistry \
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which, to )

Adds that the specified registry suite to another registry suite.

Use this macros to automatically create test registry suite hierarchy. For example, if you want to create the following hierarchy:

- Math
  - IntegerMath
  - FloatMath
    - FastFloat
    - StandardFloat

You can do this automatically with:

CPPUNIT_REGISTRY_ADD( "FastFloat", "FloatMath" );
CPPUNIT_REGISTRY_ADD( "IntegerMath", "Math" );
CPPUNIT_REGISTRY_ADD( "FloatMath", "Math" );
CPPUNIT_REGISTRY_ADD( "StandardFloat", "FloatMath" );

There is no specific order of declaration. Think of it as declaring links.

You register the test in each suite using CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.

Parameters

  which | Name of the registry suite to add to the registry suite named to.
  to | Name of the registry suite which is added to.

See also
  CPPUNIT_REGISTRY_ADD_TO_DEFAULT, CPPUNIT_TEST_SUITE_NAMED_REGISTRATION.

## ◆ CPPUNIT_REGISTRY_ADD_TO_DEFAULT

#define CPPUNIT_REGISTRY_ADD_TO_DEFAULT | ( |  | which | ) |

Value:
static CPPUNIT_NS::AutoRegisterRegistry \
CPPUNIT_MAKE_UNIQUE_NAME( autoRegisterRegistry__ )( which )

Adds that the specified registry suite to the default registry suite.

This macro is just like CPPUNIT_REGISTRY_ADD except the specified registry suite is added to the default suite (root suite).

Parameters

  which | Name of the registry suite to add to the default registry suite.

See also
  CPPUNIT_REGISTRY_ADD.

## ◆ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION

#define CPPUNIT_TEST_SUITE_NAMED_REGISTRATION | ( |  | ATestFixtureType,
|  |  | suiteName
| ) |  |

Value:
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )(suiteName)

Adds the specified fixture suite to the specified registry suite.

This macro declares a static variable whose construction causes a test suite factory to be inserted in the global registry suite of the specified name. The registry is available by calling the static function CppUnit::TestFactoryRegistry::getRegistry().

For the suite name, use a string returned by a static function rather than a hardcoded string. That way, you can know what are the name of named registry and you don't risk mistyping the registry name.

// MySuites.h
namespace MySuites {
std::string math() {
return "Math";
}
}
// ComplexNumberTest.cpp
#include "MySuites.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ComplexNumberTest, MySuites::math() );

Parameters

  ATestFixtureType | Type of the test case class.
  suiteName | Name of the global registry suite the test suite is registered into.

Warning
  This macro should be used only once per line of code (the line number is used to name a hidden static variable).

See also
  CPPUNIT_TEST_SUITE_REGISTRATION
  CPPUNIT_REGISTRY_ADD_TO_DEFAULT
  CPPUNIT_REGISTRY_ADD
  CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, CppUnit::TestFactoryRegistry..

## ◆ CPPUNIT_TEST_SUITE_REGISTRATION

#define CPPUNIT_TEST_SUITE_REGISTRATION | ( |  | ATestFixtureType | ) |

Value:
static CPPUNIT_NS::AutoRegisterSuite< ATestFixtureType > \
CPPUNIT_MAKE_UNIQUE_NAME(autoRegisterRegistry__ )

Adds the specified fixture suite to the unnamed registry.

This macro declares a static variable whose construction causes a test suite factory to be inserted in a global registry of such factories. The registry is available by calling the static function CppUnit::TestFactoryRegistry::getRegistry().

Parameters

  ATestFixtureType | Type of the test case class.

Warning
  This macro should be used only once per line of code (the line number is used to name a hidden static variable).

See also
  CPPUNIT_TEST_SUITE_NAMED_REGISTRATION
  CPPUNIT_REGISTRY_ADD_TO_DEFAULT
  CPPUNIT_REGISTRY_ADD
  CPPUNIT_TEST_SUITE, CppUnit::AutoRegisterSuite, CppUnit::TestFactoryRegistry.

| Send comments to: CppUnit Developers