例えば:
プロダクション.cpp
int func1()
{
return 7;
}
void func2()
{
printf("func2");
}
void productionCode()
{
int x = func1();
if(x==7) func2();
}
TestProduction.cpp
int func1()
{
return mock().actualCall("func1").
returnIntValue();
}
void setExpFunc1(int x)
{
mock().expectOneCall("func1")
andReturnValue(x);
}
TEST(testGroupSample, testMockFunc1)
{
setExpFunc1(8);
// this will call mock func1()
productionCode();
}
TEST(testGroupSample, testRealFunc2)
{
// this will call real func1()
productionCode();
}
私の理解では、 func1() がモックされたとき、実際の関数をテストする方法はありません。
以下のサンプル コードは、私がやろうとしていることの単なるアイデアです。
内部で多くの関数を呼び出す多くの関数をテストする必要があるためです。時々、他の関数の実際の結果を気にしないので、それを嘲笑しましたが、テストしている関数内で呼び出すときに実際の関数の動作をテストしたい場合、その関数は実行できないため、実行できませんすでに嘲笑されています。
また、本番コードを変更せずに、テスト コードのみを変更できることを願っています。