CppUnit project page FAQ

Public Member Functions | Protected Member Functions
Test Class Reference

Base class for all test objects.All test objects should be a subclass of Test. Some test objects, TestCase for example, represent one individual test. Other test objects, such as TestSuite, are comprised of several tests. More...

#include <Test.h>

Inheritance diagram for Test:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual ~Test ()
virtual void run (TestResult *result)=0
 Run the test, collecting results.
virtual int countTestCases () const =0
 Return the number of test cases invoked by run().
virtual int getChildTestCount () const =0
 Returns the number of direct child of the test.
virtual TestgetChildTestAt (int index) const
 Returns the child test of the specified index.
virtual std::string getName () const =0
 Returns the test name.
virtual bool findTestPath (const std::string &testName, TestPath &testPath) const
 Finds the test with the specified name and its parents test.
virtual bool findTestPath (const Test *test, TestPath &testPath) const
 Finds the specified test and its parents test.
virtual TestfindTest (const std::string &testName) const
 Finds the test with the specified name in the hierarchy.
virtual TestPath resolveTestPath (const std::string &testPath) const
 Resolved the specified test path with this test acting as 'root'.

Protected Member Functions

virtual void checkIsValidIndex (int index) const
virtual TestdoGetChildTestAt (int index) const =0
 Returns the child test of the specified valid index.

Detailed Description

Base class for all test objects.

All test objects should be a subclass of Test. Some test objects, TestCase for example, represent one individual test. Other test objects, such as TestSuite, are comprised of several tests.

When a Test is run, the result is collected by a TestResult object.

See also:
TestCase
TestSuite

Constructor & Destructor Documentation

virtual Test::~Test ( )
inlinevirtual

Member Function Documentation

void Test::checkIsValidIndex ( int  index) const
protectedvirtual

Throws an exception if the specified index is invalid.

Parameters:
indexZero base index of a child test.
Exceptions:
std::out_of_rangeis index is < 0 or >= getChildTestCount().
virtual int Test::countTestCases ( ) const
pure virtual

Return the number of test cases invoked by run().

The base unit of testing is the class TestCase. This method returns the number of TestCase objects invoked by the run() method.

Implemented in RepeatedTest, TestDecorator, TestComposite, and TestLeaf.

virtual Test* Test::doGetChildTestAt ( int  index) const
protectedpure virtual

Returns the child test of the specified valid index.

Parameters:
indexZero based valid index of the child test to return.
Returns:
Pointer on the test. Never NULL.

Implemented in TestRunner::WrappingSuite, TestSuite, TestLeaf, and TestDecorator.

Test * Test::findTest ( const std::string &  testName) const
virtual

Finds the test with the specified name in the hierarchy.

Parameters:
testNameName of the test to find.
Returns:
Pointer on the first test found that is named testName. Never NULL.
Exceptions:
std::invalid_argumentif no test named testName is found.
bool Test::findTestPath ( const std::string &  testName,
TestPath testPath 
) const
virtual

Finds the test with the specified name and its parents test.

Parameters:
testNameName of the test to find.
testPathIf the test is found, then all the tests traversed to access test are added to testPath, including this and test.
Returns:
true if a test with the specified name is found, false otherwise.
bool Test::findTestPath ( const Test test,
TestPath testPath 
) const
virtual

Finds the specified test and its parents test.

Parameters:
testTest to find.
testPathIf the test is found, then all the tests traversed to access test are added to testPath, including this and test.
Returns:
true if the specified test is found, false otherwise.
CPPUNIT_NS_BEGIN Test * Test::getChildTestAt ( int  index) const
virtual

Returns the child test of the specified index.

This method test if the index is valid, then call doGetChildTestAt() if the index is valid. Otherwise std::out_of_range exception is thrown.

You should override doGetChildTestAt() method.

Parameters:
indexZero based index of the child test to return.
Returns:
Pointer on the test. Never NULL.
Exceptions:
std::out_of_rangeis index is < 0 or >= getChildTestCount().
virtual int Test::getChildTestCount ( ) const
pure virtual

Returns the number of direct child of the test.

Implemented in TestRunner::WrappingSuite, TestSuite, TestLeaf, and TestDecorator.

virtual std::string Test::getName ( ) const
pure virtual

Returns the test name.

Each test has a name. This name may be used to find the test in a suite or registry of tests.

Implemented in TestRunner::WrappingSuite, TestCase, TestDecorator, TestComposite, and TestCaseDecorator.

TestPath Test::resolveTestPath ( const std::string &  testPath) const
virtual

Resolved the specified test path with this test acting as 'root'.

Parameters:
testPathTest path string to resolve.
Returns:
Resolved TestPath.
Exceptions:
std::invalid_argumentif testPath could not be resolved.
See also:
TestPath.
virtual void Test::run ( TestResult result)
pure virtual

Run the test, collecting results.

Implemented in TestRunner::WrappingSuite, TestCase, TestDecorator, RepeatedTest, TestComposite, and TestSetUp.


The documentation for this class was generated from the following files:

Send comments to:
CppUnit Developers