EXPECT_CALL和ON_CALL是设计用于模拟对象的宏。通常用例如下:
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, _)); ...
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); ...
EXPECT_CALL(turtle, Forward(100)); cardinality:调用次数 // turtle::Forward 将预期调用1次 EXPECT_CALL(turtle, Forward(100)).Times(1); // turtle::Forward 将预期调用至少1次 EXPECT_CALL(turtle, Forward(100)).Times(AtLeast(1)); action:满足期望做什么 using ::testing::Return; ... // GetX...
初识Gmock是之前分析GTest源码时,它的源码和GTest源码在同一个代码仓库中(https://github.com/google/googletest)。本文我将以目前最新的Gmock1.7版本为范例,分析其实现原理。(转载请指明出于breaksoftware的csdn博客)
EXPECT_CALL(::sendto_mock(_, _, _, _, _, _)) .Times(1) .WillOnce(Return(0)); // 模拟 sendto 成功发送 // 创建 UDPSink 实例 UDPSink sink("127.0.0.1", 8080); // 创建一个虚拟的日志消息 spdlog::details::log_msg msg;
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()的错误。