我有一个 boost 测试用例,它使用 BOOST_CHECK*
进行一些检查,因此失败不会立即停止测试。但在某些时候,如果到目前为止发生任何测试失败,我想停止,因为如果健全性检查失败,剩下的测试就没有意义了?例如:
BOOST_AUTO_TEST_CASE(test_something) {
Foo foo;
BOOST_CHECK(foo.is_initialized());
BOOST_CHECK(foo.is_ready());
BOOST_CHECK(foo.is_connected());
// ...
// I want something like this:
BOOST_REQUIRE_CHECKS_HAVE_PASSED();
foo.do_something();
BOOST_CHECK(foo.is_successful());
}
最佳答案
可以检查当前测试的状态,如下所示:
namespace ut = boost::unit_test;
auto test_id = ut::framework::current_test_case().p_id;
BOOST_REQUIRE(ut::results_collector.results(test_id).passed());
关于c++ - 我如何判断到目前为止是否有任何 BOOST_CHECK 测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27002183/