TestCase |
The class TestCase (see Figure C-18) represents a test object. Its purpose is to run test methods and thereby produce test results.
TestCase may be used in a number of ways. The simplest way to write a test object is to create a subclass of TestCase that overrides runTest() with a custom test method. To run the test object, call the run( ) method, which returns a TestResult .
More commonly, a subclass of TestFixture is created with multiple test methods. TestRunner then uses TestCaller to run the test methods, creating a new instance of TestCase for each one.
TestCase belongs to the namespace CppUnit . It is declared in TestCase.h and implemented in TestCase.cpp .
class TestCase : public Test, public TestFixture
Constructs a TestCase with the given name.
The default constructor used by TestCaller to create a temporary TestCase . Should not be used directly, since it creates a TestCase with no name.
A destructor.
Returns 1, the number of test cases contained in a base TestCase . Descendants of TestCase may contain multiple test cases.
Returns the TestCase name.
A convenience method that runs this TestCase and returns a new TestResult containing the results.
A method that runs the test, catches any failures or errors, and collects the results in result . The sequence of calls is: setUp( ) , runTest( ) , tearDown( ) . This method is the interface that the framework normally uses to run tests.
Returns a string representation of this TestCase , including the class name and TestCase name.
A Protected method that returns a default empty TestResult . Used by run( ) .
A Protected method representing the actual test method. The default version does nothing. May be overridden by descendants of TestCase to implement actual tests. The overridden runTest( ) method contains the test assertions that result in success or failure of the unit test.
A copy constructor declared private to prevent its use.
A copy operator declared private to prevent its use.
The TestCase name ( private ).