Creating a CActiveTestFixture derived class
TEFUnit provides a simple way of running unit tests within an active
environment. In this case unit tests need to be included in a
CActiveTestFixture
derived class and each test case needs to be
added to a suite for that fixture. Each derived test fixture also requires a
static CreateSuiteL()
function to provide the TEFUnit framework
with the suite hierarchy information.
CActiveTestFixture
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.
CActiveTestFixture
has four virtual member functions which
are implemented in the base class for use by the TEFUnit framework:
-
ConstructEnvL
is used to install the active environment
-
DestroyEnvL
is used to destroy the active environment
-
StartEnvL
is used to start the active environment
-
StopEnvL
is used to stop the active environment
For the TEFUnit MACROs to operate, specific naming convention must be
followed. Each test case must start with “Test” followed by a unique name and
each CActiveTestFixture
derived class must start with “CTest”.
Example derived class header file:
#ifndef __ACTIVE_TEST_SUITE__
#define __ACTIVE_TEST_SUITE__
// Only one TEFUnit header file will ever be required
#include "TEFUnit.h"
class CTestAsyncSuite : public CActiveTestFixture
{
public:
// SetUp and TearDown code
virtual void SetupL();
virtual void TearDownL();
// virtual active environment functions not required (Use base class).
// 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 // __ACTIVE_TEST_SUITE__
Example derived class cpp file:
#include "CTestAsyncSuite.h"
void CTestAsyncSuite::SetupL()
{
//Some Setup Code here
}
void CTestAsyncSuite::TearDownL()
{
//Some TearDown Code here
}
void CTestAsyncSuite::TestOne()
{
// Add a unit test here
}
void CTestAsyncSuite::TestTwo()
{
// Add a unit test here
}
CTestSuite* CActiveTestSuite::CreateSuiteL( const TDesC& aName )
{
SUB_SUITE;
ADD_ASYNC_TEST_STEP( TestOne ); // Add test case one to the suite
ADD_ASYNC_TEST_STEP( TestTwo ); // Add test case two to the suite
END_SUITE;
}