我知道EXPECT_CALL
应该用于模拟类及其对象/方法。但是是否有可能使用它来期望调用本地方法?
void Sample::Init()
{
// some codes here...
auto enabled = isFeatureEnabled();
//some other things here
}
bool Sample::isFeatureEnabled()
{
return lights_ and sounds_;
}
我想EXPECT_CALL isFeatureEnabled()
-这有可能吗?
答案 0 :(得分:1)
您可以尝试一下,我发现这种方法很有用:
class template_method_base {
public:
void execute(std::string s1, std::string s2) {
delegate(s1 + s2);
}
private:
virtual void delegate(std::string s) = 0;
};
class template_method_testable : public template_method_base {
public:
MOCK_METHOD1(delegate, void(std::string s));
};
TEST(TestingTemplateMethod, shouldDelegateCallFromExecute) {
template_method_testable testable_obj{};
EXPECT_CALL(testable_obj, delegate("AB"));
testable_obj.execute("A", "B");
}