Creating stub functionality in C++
<p>I have a piece of C++ code whose unit testing is to be done. e.g.</p>

<pre><code>//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-&gt;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
}
</code></pre>

<p>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.</p>

<p>I have a test app whose code is as follows</p>

<pre><code>//testcode.cpp
#include "totest.h"
int main()
{
    ToTest *tt = new ToTest();
    tt-&gt;function_totest();
    //some asserts
    return 0;
}
</code></pre>

<p>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.</p>

<p>Please provide some suggestions to design this requirement.
Thanks,
Ankur</p>
