ADC Home > Reference Library > Reference > Tools > Xcode > CPlusTest Reference

 


TestCase

Inherits from:
Declared In:

Overview

Base class for test cases in CPlusTest.

Discussion

Unit tests in CPlusTest are implemented by writing individual test methods and grouping them into test cases that use a common fixture. This fixture is common but not shared; one fixture is created and torn down around each invocation of a test method. There should be one instance of a test case subclass per test method in the subclass. This enables the tests to be made part of the "all tests" test suite automatically.



Functions

name
Gets the name of the test.
run
Runs the test, recording the results.
setUp
Sets up any necessary state before a test is run.
tearDown
Tears down any state previously set up in setUp after a test has run.
TestCase
Principal constructor for the TestCase class (must be invoked by subclasses).
~TestCase
Destructor for the TestCase class.

name


Gets the name of the test.

public

virtual const std::string& name();
Discussion

Gets the name of the test, which is derived at construction from the name of the invocation passed to the constructor. It is in the format "ClassName::testName". Subclasses should not need to override this method.


run


Runs the test, recording the results.

public

virtual void run( TestRun& run);
Parameters
run
A TestRun in which test success or failure is recorded.
Discussion

Runs the test and record the success or any failure information in the passed TestRun. This will invoke the test's setUp and tearDown methods around the actual invocation of the test, and will use the invocation passed to the constructor to invoke the test.


setUp


Sets up any necessary state before a test is run.

public

virtual void setUp();
Discussion

Sets up any state needed by a test immediately before it is run. State used by a test should be set up here rather than in the test constructor so that it is only present when necessary. Subclasses may but do not need to invoke TestCase::setUp.


tearDown


Tears down any state previously set up in setUp after a test has run.

public

virtual void tearDown();
Discussion

Tears down any state needed by a test immediately after it has run. State used by a test should be torn down here rather than in the test destructor so that it is only present as long as necessary. Subclasses may but do not need to invoke TestCase::tearDown.


TestCase


Principal constructor for the TestCase class (must be invoked by subclasses).

public

TestCase( TestInvocation *invocation);
Parameters
invocation
An invocation representing the individual test method to run.
Discussion

The principal constructor for the TestCase class, which must be invoked by all subclasses. It derives the name of the test from the invocation it is passed. It also registers the test with the "all tests" test suite.


~TestCase


Destructor for the TestCase class.

public

virtual ~TestCase();
Discussion

Destructor for the TestCase class. It removes the test from the "all tests" test suite.


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.
Last Updated: 2008-03-11