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 ®istry = TestFactoryRegistry::getRegistry( );
TestSuite *suite = registry.makeTest( );
TestFactoryRegistry belongs to the namespace
CppUnit. It is declared in
extensions/TestFactoryRegistry.h and implemented
in TestFactoryRegistry.cpp.
![]() |
Declaration
class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access
