我希望能够在测试失败的情况下将数据保存到磁盘。有没有办法在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);
}
答案 0 :(得分:6)
有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
}
}