7.2 Architecture

     

CppUnit contains 24 ordinary classes, 4 abstract classes, 7 template classes, and several nested classes and helper macros. Everything belongs to the namespace "CppUnit" or one of its subordinate namespaces. The CppUnit namespaces are shown in Figure 7-1.

Figure 7-1. The CppUnit namespaces
figs/utf_0701.gif

Most of the code belongs to the main namespace, "CppUnit." The namespace "Asserter" contains assertion functions used in test assert macros. "TestAssert" contains the function template assertEquals() and the method assertDoubleEquals() . The "Ui" namespaces contain text, MFC, and QT versions of TestRunner .

Just as in JUnit, CppUnit's central design element is an abstract interface called Test implemented by classes named TestCase and TestSuite , as shown in Figure 7-2.

Figure 7-2. The key Test classes
figs/utf_0702.gif

TestCase represents an actual test object, and TestSuite is a composite of other Test objects. The class TestFixture represents the test fixture interface implemented by TestCase , with setUp() and tearDown( ) methods .

The object architecture for collecting test results is more complex than in JUnit. The key classes pertaining to test result handling are shown in Figure 7-3.

Figure 7-3. Classes to collect test results
figs/utf_0703.gif

The class TestResult receives test results as Test objects are run. However, it does not store the results but instead uses the TestListener interface to inform observers of test results. The TestListener subclass TestResultCollector stores the test results for reporting. As shown in Figure 7-3, these classes are derived from SynchronizedObject . This allows their operations to be mutex-protected so that tests and listeners may execute safely in separate, concurrent threads.

Output of test results is handled by classes implementing the Outputter interface, shown in Figure 7-4.

Figure 7-4. The Outputter classes for printing test results
figs/utf_0704.gif

The Outputter objects print the test results in human-readable text format, as an XML document, or in an IDE-compatible ("compiler") format.

The class TestRunner provides a convenient interface for running tests. CppUnit includes a generic text TestRunner as well as GUI versions of TestRunner for use in Qt and MFC development environments.

Appendix C is a class reference giving the low-level design details of CppUnit.



Unit Test Frameworks
Unit Test Frameworks
ISBN: 0596006896
EAN: 2147483647
Year: 2006
Pages: 146
Authors: Paul Hamill

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net