[英]GTest test case “EXPECT_CALL” compilation error
#include "gtest\gtest.h"
using namespace testing;
class MyGTest : public Test
{
public:
void f(){}
void g(){
f();
f();
}
};
TEST_F(MyGTest, first)
{
EXPECT_CALL(*this, f()).Times(2);
g();
}
VC2013 says: VC2013说:
"MyGTest_first_Test" has no member "gmock_f"
What does it mean? 这是什么意思? I expect the call to g() to call f() for 2 times.
我希望调用g()来调用f()2次。 Any syntax error I made?
我做的任何语法错误?
Not a syntax error, more like a completely wrong approach. 不是语法错误,更像是一种完全错误的方法。 Macro
EXPECT_CALL
is used to set expectations of function calls from mock objects. 宏
EXPECT_CALL
用于设置模拟对象的函数调用的期望。 The problem is that you are not passing a mock object to EXPECT_CALL
(an object of class whose definition contains MOCK_METHODN
), you are dereferencing this
pointer instead. 问题是您没有将模拟对象传递给
EXPECT_CALL
(其定义包含MOCK_METHODN
的类的对象),而是取消引用this
指针。 In doing so, you are passing an object of your test class to EXPECT_CALL
. 这样做,您将测试类的对象传递给
EXPECT_CALL
。 This is why the compiler error mentiones class MyGTest_first_Test
, gmock creates a new class in the background, and its name is a combination of fixture class name ( MyGTest
), test case name ( first
) and base class name ( Test
). 这就是为什么编译器错误提到类
MyGTest_first_Test
,gmock在后台创建一个新类,其名称是fixture类名( MyGTest
),测试用例名( first
)和基类名( Test
)的组合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.