I have a piece of C++ code whose unit testing is to be done. e.g.
//totest.h
#include "lowerlayer.h"
class ToTest
{
LowerLayer *ll;
public:
ToTest();
void function_totest();
};
//totest.cpp
#include "totest.h"
ToTest::ToTest()
{
ll = new LowerLayer();
}
void ToTest::function_totest()
{
ll->function_lowerlayer();
}
//lowerlayer.h
class LowerLayer
{
public:
LowerLayer();
void function_lowerlayer();
};
//lowerlayer.cpp
#include "lowerlayer.h"
LowerLayer::LowerLayer()
{
//do nothing
}
void LowerLayer::function_lowerlayer()
{
//do nothing
}
The four files viz. totest.h, totest.cpp, lowerlayer.h and lowerlayer.cpp are the production code files are are not supposed to be modified for unit testing.
I have a test app whose code is as follows
//testcode.cpp
#include "totest.h"
int main()
{
ToTest *tt = new ToTest();
tt->function_totest();
//some asserts
return 0;
}
Now, I have to create a stub functionality for class LowerLayer and its functions. When function function_lowerlayer is called from function function_totest, both stub and real functions (one at a time) should be called using a controlling flag from testcode application.
Please provide some suggestions to design this requirement. Thanks, Ankur