TestSuite

   
TestSuite

Description

The class TestSuite (see Figure C-31) implements the interface Test . It is a composite of Test objects. Since the contained Test objects may be instances of TestCase , TestSuite , or any other subclass of Test , this allows hierarchies of Test classes to be assembled and run as a unit. A TestSuite is run just like a TestCase : by calling its run( ) method and passing in a TestResult to receive the results. The TestSuite then sequentially runs the Test objects it contains.

A TestSuite takes ownership of all Test objects added to it and deletes them in its destructor.

TestSuite belongs to the namespace CppUnit . It is declared in the file TestSuite.h and implemented in the file TestSuite.cpp .

Figure C-31. The class TestSuite
figs/utf_ac31.gif

Declaration

 class TestSuite : public Test 

Constructors/Destructors


TestSuite(string name = "")

Constructs a TestSuite , optionally giving it a name.


virtual ~TestSuite( )

A destructor. Deletes all the contained Test objects.

Public Methods


void addTest(Test *test)

Adds a Test to this TestSuite .


int countTestCases( ) const

Returns the total number of TestCase objects to be run by this TestSuite , by recursively calling countTestCases( ) on all the contained Test objects.


virtual void deleteContents( )

Deletes all the contained Test objects.


string getName( ) const

Returns the name of this TestSuite .


const vector<Test *> &getTests( ) const

Returns the collection of contained Test objects.


void run(TestResult *result)

Runs the Test objects and receives the results in result .


string toString( ) const

Returns a string representation of this TestSuite .

Protected/Private Methods


TestSuite(const TestSuite &other)

A copy constructor declared private to prevent its use.


TestSuite& operator=(const TestSuite &other)

A copy operator declared private to prevent its use.

Attributes


const string m_name

The name of this TestSuite . May be empty ( private ).


vector<Test *> m_tests

The collection of Test objects belonging to this TestSuite ( private ).



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