c++ - 我如何控制我的 gmock 何时被验证?

标签 c++ qt googlemock qtestlib

使用“另一个测试框架”(Qt),我想控制何时验证谷歌模拟:

void MyQtTest::test_ThisAndThat() {
     MyMock mock;
     EXPECT_CALL(mock, foo(1));

     system_under_test.bar();

     //VERIFY_EXPECTATIONS(mock)
 }

但我在 Cookbook 中找不到任何相关信息.

最佳答案

这是我在类似情况下通常做的:

void MyQtTest::test_ThisAndThat()
{
    MyMock mock;
    EXPECT_CALL(mock, foo(1));
    system_under_test.bar();

    Mock::VerifyAndClearExpectations(&mock);
}

引用: https://github.com/google/googletest/blob/master/docs/gmock_cheat_sheet.md#verifying-and-resetting-a-mock

编辑:修复损坏的链接

第二次编辑:再次修复损坏的链接

关于c++ - 我如何控制我的 gmock 何时被验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26884226/

相关文章:

c++ - 在 lambda 闭包中复制的 const 对象不可变

android - 在 Android 应用程序上部署 Qt 时出错

qt - QML 动态列宽

c++ - Google Mock,使用另一个参数的参数匹配器

c++ - gmock.h 不包含在我的 Google 测试的外部依赖项中

c++ - 在 Qt Creator 中禁用 "The build directory needs to be at the same level as the source directory"警告

c++ - 为什么 std::find_if 和相关函数没有对整个容器进行重载?

c# - 使用 DirectShow 捕获相机

qt - QML:有条件地设置属性组的不同属性

c++ - 将模拟对象作为函数的参数传递