The class TestDecorator (see Figure C-19) allows the functionality of a Test to be extended without subclassing it. TestDecorator implements the Test interface and thus can be run like any other Test . When constructed , it takes a reference to another Test that it "decorates," or wraps. A TestDecorator modifies the decorated Test by performing other operations before or after running it.

The classes RepeatedTest and TestSetUp are subclasses of TestDecorator and provide practical examples of its usage. The base implementation of TestDecorator simply is a wrapper for a Test and does not change its operation.

TestDecorator belongs to the namespace CppUnit . It is declared and implemented in extensions/TestDecorator.h .

Figure C-19. The class TestDecorator


 class TestDecorator : public Test 


TestDecorator(Test *test)

Constructs a TestDecorator to decorate test .

~TestDecorator( )

A destructor. Does not delete the decorated Test .

Public Methods

int countTestCases( ) const

Returns the value of countTestCases( ) for the decorated Test .

string getName( ) const

Returns the name of the decorated Test .

void run(TestResult *result)

Calls run(result) on the decorated Test .

string toString( ) const

Returns the value of toString( ) for the decorated Test .

Protected/Private Methods

TestDecorator(const TestDecorator &other)

A copy constructor declared private to prevent its use.

void operator=(const TestDecorator &other)

A copy operator declared private to prevent its use.


Test *m_test

The Test decorated by this TestDecorator ( protected ).

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

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