4
我的一些代码抛出使用打印exception.what()在谷歌测试
if (failure)
throw std::runtime_error("a bad thing happened: ...");
我使用谷歌测试及TeamCity的自动执行我的测试。它运行在Windows上,所以我使用--gtest_catch_exceptions参数来报告测试失败,如果发生意外的异常。然而,谷歌测试只是通过一条消息,如
Exception thrown with code 0xe06d7363 in the test body.
in (null) line -1
这样的消息不是很有帮助。我宁愿像
Exception thrown: "a bad thing happened: ..."
的消息我有一个实现方法
OnTestPartResult(const ::testing::TestPartResult& test_part_result)
定制TestListener但它好像有到被谷歌测试捕捉到的异常没有提及。是否有任何其他方式向std :: cout或其他地方报告异常?
请注意,我不能使用
try
{
return RUN_ALL_TESTS();
}
catch (std::exception& e)
{
std::cout << "EXCEPTION: " << e.what();
return -1;
}
catch (...)
{
return -1;
}
没有--gtest_catch_exceptions,因为测试执行,然后获取第一异常“取消”。
我也不想更改投掷代码。
感谢您的任何想法!
您使用的是哪种googletest版本?它看起来像树干支持自动输出字符串就像你想要的。 – 2011-01-11 08:54:27