我希望能够将数据保存到磁盘,以防测试失败。在googletest框架内有什么方法可以做到这一点吗?
TEST_F(test_similarity,are_similar) {
ASSERT_GT(1e-10,norm(im0,im1));
// If test fails save images to disk for comparison:
imwrite("im0.png",im0);
imwrite("im1.png",im1);
}
最佳答案
有Test::HasFailure()
,Test::HasNonfatalFailure()
和Test::HasFatalFailure()
函数,如果发生(致命/非致命)故障,则返回true
。您可以使用它们进行检查。
TEST_F(test_similarity,are_similar) {
EXPECT_GT(1e-10,norm(im0,im1)); // Note the change to EXPECT
// If test fails save images to disk for comparison:
if(HasFailure()) { // if not in a TEST, use ::testing::Test::HasFailure()
imwrite("im0.png",im0);
imwrite("im1.png",im1);
FAIL(); //We want to fail fatally; use ADD_FAILURE() to fail non-fatally
}
}
看
https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#checking-for-failures-in-the-current-test以获得详细信息。
关于c++ - googletest:如果测试失败,则执行其他操作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21892841/