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);
}
所以,我的問題是
我不知道如何控制,這將在我的測試對象的功能代碼調用函數的輸出參數。
有何評論?多謝。