谷歌测试框架最佳实践,以从TestEventListener失败测试

时间:2015-11-22 17:16:52

标签: c++ unit-testing googletest

我有TestEventListener,如果超过某个限制,则测试失败。我在OnTestEnd中检查了test_info.result()->elapsed_time(),我用GTEST_FAIL触发了错误。

void TimeMonitor::OnTestEnd(const ::testing::TestInfo& test_info)
{
  ...

  GTEST_FAIL()
    << "This test took "
    << test_info.result()->elapsed_time() << " ms "
    << "instead the expected " << expected << " ms.";
}

这适用于一个非常烦人的异常 - 错误报告代码行指向GTEST_FAIL()所在的位置。我知道这段代码是正确的,我想指出那个失败的测试负责人。

如何更改代码以打印测试头位置?

0 个答案:

没有答案
相关问题