我的一些代码使用
if (failure)
throw std::runtime_error("a bad thing happened: ...");
我正在使用 Google Test 和 TeamCity 自动执行我的测试。它在 Windows 上运行,因此如果发生意外异常,我使用 --gtest_catch_exceptions 参数将测试报告为失败。但是,Google Test 只是通过以下消息使测试失败
Exception thrown with code 0xe06d7363 in the test body.
in (null) line -1
这不是很有帮助。我宁愿有这样的消息
Exception thrown: "a bad thing happened: ..."
我有一个实现该方法的自定义 TestListener
OnTestPartResult( const ::testing::TestPartResult& test_part_result)
但似乎没有提到谷歌测试捕获的异常。有没有其他方法可以向 std::cout 或其他地方报告异常?
请注意,我不能使用
try
{
return RUN_ALL_TESTS();
}
catch (std::exception& e)
{
std::cout << "EXCEPTION: " << e.what();
return -1;
}
catch (...)
{
return -1;
}
没有 --gtest_catch_exceptions,因为测试执行会在第一个异常时“取消”。
我也不想更改投掷代码。
感谢您的任何想法!