EXPECT_CALL和ON_CALL是设计用于模拟对象的宏。通常用例如下:
using ::testing::_;// 期望turtle.GoTo(50, y)被调用,y为任意值EXPECT_CALL(turtle, GoTo(50, _)); 如果不对参数做任何限制,则可以省略参数表: // 期望turtle.Forward(x)被调用,x为任意值EXPECT_CALL(turtle, Forward);// 期望turtle.GoTo(x, y)被调用,x和y为任意值EXPECT_CALL(turtle, GoTo); ...
初识Gmock是之前分析GTest源码时,它的源码和GTest源码在同一个代码仓库中(https://github.com/google/googletest)。本文我将以目前最新的Gmock1.7版本为范例,分析其实现原理。(转载请指明出于breaksoftware的csdn博客)
1 2 // 期望turtle.Forward(100)被调用 EXPECT_CALL(turtle, Forward(100)); 这里的100等价于Eq(100)。通配符_表示任意值:1 2 3 using ::testing::_; // 期望turtle.GoTo(50, y)被调用,y为任意值 EXPECT_CALL(turtle, GoTo(50, _)); ...
EXPECT_FALSE( condition ); ASSERT_FALSE( condition ); //二元比较 //等于 EXPECT_EQ( val1 , val2 ); ASSERT_EQ( val1 , val2 ); //不等于,注意比较空指针的时候,使用EXPECT_NE( ptr , nullptr) 而不是 EXPECT_NE( ptr , NULL)
{ EXPECT_CALL(*mockNetwork, send_data("Hello")) .WillOnce(Return(true)); EXPECT_TRUE(client->send("Hello")); } TEST_F(NetworkClientTest, SendDataFailure) { EXPECT_CALL(*mockNetwork, send_data("Hello")) .WillOnce(Return(false)); EXPECT_FALSE(client->send("Hello")); } TEST_F(...
All the standard gtest EXPECT and ASSERT macros support at least 2 ways (that I know of) for attaching arbitrary information to their output to provide context in case of failure (<< at the end, or ScopedTrace). EXPECT_CALL, however, doesn't support either of these mechanisms. I haven'...
这三个断言并不具体测试某个值或表达式,而是直接产生成功或失败。象其它用于测试的断言宏一样,你也可以为它们自定义失败信息。SUCCEED();产生一个成功断言,注意,这并不表示整个测试成功。一次测试成功的充分必要条件是:在整个测试期间没有出现失败的断言。注:SUCCEED() 宏目前不会产生任何输出,实际上它只是被...
From what I can tell (by reading the documentation), this may be a design issue. If I use ON_CALL to create a default action and use an EXPECT_CALL for different tests, the EXPECT_CALL will generate an unexpected mock function call if th...
特别是,如果使用mock并且死亡测试语句调用了一些mock方法,则父进程将认为调用从未发生。 因此,可能需要在EXPECT_DEATH宏内移动EXPECT_CALL语句。 EXPECT_EQ(htonl(blah),blah_blah)在opt模式下生成奇怪的编译器错误。这是googletest错误吗? 事实上,是htonl()的错误。