Name

TestFactoryRegistry

Description

The class TestFactoryRegistry (see Figure C-21) is a subclass of TestFactory. It acts as both a registry and a factory for Test objects. It registers Tests, and it produces TestSuites containing registered Tests. Rather than containing the registered Test objects themselves, it contains a TestFactory for each one.

The default registry is a TestFactoryRegistry named “All Tests.” Named instances of TestFactoryRegistry may also be created.

The macro CPPUNIT_TEST_SUITE_REGISTRATION( ) takes a Test and adds a TestFactory for it to the default registry. The macro CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ) similarly adds a TestFactory to a named registry. Calling a registry’s makeTest( ) method creates a TestSuite containing all the registered Tests, demonstrating the main usefulness of TestFactoryRegistry.

The singleton NamedRegistries manages all instances of TestFactoryRegistry.

The following code snippet registers the Test class BookTest in the default registry and creates a TestSuite containing it:

CPPUNIT_TEST_SUITE_REGISTRATION( BookTest );
TestFactoryRegistry &registry = TestFactoryRegistry::getRegistry( );
TestSuite *suite = registry.makeTest( );

TestFactoryRegistry belongs to the namespace CppUnit. It is declared in extensions/TestFactoryRegistry.h and implemented in TestFactoryRegistry.cpp.

The class TestFactoryRegistry
Figure C-21. The class TestFactoryRegistry

Declaration

class ...

Get Unit Test Frameworks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.