Creating a CTestFixture derived class

You must derive a test fixture class from the CTestFixture base class provided by the framework. Your test fixture class contains your test cases which may be structured into a hierarchy of test suites. You must provide a static CreateSuiteL() function in your test fixture to supply your hierarchy to the framework.

CTestFixture defines virtual SetupL() and TearDownL() functions which the framework calls before and after executing the tests in the fixture. You can implement these in your fixture to perform configuration tasks common to all the tests in the hierarchy and to tidy up afterwards.

For the TEFUnit MACROs to operate, specific naming convention must be followed. Each test case must start with “Test” followed by a unique name. Each CTestFixture derived class must start with “CTest”.

Example derived class header file:

#ifndef __TEST_SUITE__
#define __TEST_SUITE__

// Only one TEFUnit header file will ever be required
#include "TEFUnit.h"

class CTestSuite : public CTestFixture 
    {
public:
    // SetUp and TearDown code
    virtual void SetupL();
    virtual void TearDownL();

    // Tests – can be as many as you require
    void TestOne();
    void TestTwo();

    // Create a suite of all the tests
    static CTestSuite* CreateSuiteL(const TDesC& aName);
    };

#endif // __TEST_SUITE__

Example derived class cpp file:

#include "CTestSuite.h"

void CTestSuite::SetupL()
    {
    // Add some setup code here
    }

void CTestSuite::TearDownL()
    {
    // Add some teardown code here
    }

void CTestSuite::TestOne()
    {
    // Add a unit test here
    }

void CTestSuite::TestTwo()
    {
    // Add a unit test here
    }

CTestSuite* CTestSuite::CreateSuiteL( const TDesC& aName )
    {
    SUB_SUITE;
    ADD_TEST_STEP( TestOne ); // Add test case one to the suite
    ADD_TEST_STEP( TestTwo ); // Add test case two to the suite
    END_SUITE;
    }