0
// Filter.h/cpp
class Filter
{
public:
int readInt(int* value)
{
if (value == NULL)
return 0;
*value = 15; // some logical;
return 1;
}
};
// TestTee.h/.cpp
class TestTee
{
public:
Func1(Filter* f)
{
...
int val;
f->readInt(&val);
...
}
}
现在,我需要测试TestTee课,所以我嘲笑类Filter如何使用Google测试来测试将调用包含输出参数的另一个函数的函数?
class MockFilter : public Filter
{
public:
MOCK_METHOD1(readInt, int(int*));
};
如何编写测试用例?
TEST_F(TestClass, Test1)
{
TestTee t;
MockFilter filter;
EXPECT_CALL(filter, readInt(_)).Times(1); // failed error: The mock function has no default action set, and its return type has no default value set." thrown in the test body.
/*
int val;
EXPECT_CALL(filter, readInt(&val)).Times(1);
Failed with the following error:
Expected: to be called once
Actual: never called - unsatisfied and active
*/
t.Func1(&filter);
}
所以,我的问题是
我不知道如何控制,这将在我的测试对象的功能代码调用函数的输出参数。
有何评论?多谢。