c++ - 如何将 Google Test 测试用例标记为 "expected to fail"?

标签 c++ unit-testing googletest

我想为尚未实现的功能添加一个测试用例,并将此测试用例标记为“没关系,我失败了”。

有办法吗?

编辑: 我希望执行测试,只要测试用例处于“预期失败”状态,框架就应该验证它是否失败。

编辑2: 好像我感兴趣的功能在google-test中不存在,但是the Boost Unit Test Framework中确实存在,并在 LIT .

最佳答案

EXPECT_NONFATAL_FAILURE 是您希望将预期失败的代码包装起来的内容。请注意,您必须包含 gtest-spi.h 头文件:

#include "gtest-spi.h"

 // ...

TEST_F( testclass, testname )
{
EXPECT_NONFATAL_FAILURE(
      // your code here, or just call:
      FAIL()
      ,"Some optional text that would be associated with"
      " the particular failure you were expecting, if you"
      " wanted to be sure to catch the correct failure mode" );
}

文档链接:https://github.com/google/googletest/blob/955c7f837efad184ec63e771c42542d37545eaef/docs/advanced.md#catching-failures

关于c++ - 如何将 Google Test 测试用例标记为 "expected to fail"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20785939/

相关文章:

c++ - 将共享指针设置为空

c# - 在 TFS 构建服务器上运行单元测试 Fakes Framework |错误

c++ - 如何正确地从水平阵列垂直读取数据?

c++ - 大数求和

unit-testing - 如何模拟 http.Client Do 方法

c++ - 在 Googletest 单元测试中禁用自动捕获 C++ 异常

c++ - 无法在谷歌测试中检查异常类型

googletest - 如果抛出异常指针,google test中的EXPECT_THROW能否捕获这个异常?

c++ - 将指针转换为 int 并返回类型化对象

Django单元测试: How should one test abstract models?