提升数据驱动的测试输出:"Assertion occurred in a following context"

Boost data-driven test output: "Assertion occurred in a following context"

我对以下使用 Boost 测试的最小示例的输出有疑问。

#define BOOST_TEST_MODULE ExampleTestSuite
#include <boost/test/included/unit_test.hpp>

#include <boost/test/unit_test.hpp>
using boost::unit_test::test_suite;
using boost::unit_test::framework::master_test_suite;

#include <boost/test/data/test_case.hpp>
namespace bdata = boost::unit_test::data;

BOOST_DATA_TEST_CASE(ExampleTest, bdata::xrange(2), testDatum) {

    int exp = testDatum == 0 ? 0 : 1;

    BOOST_CHECK_EQUAL(testDatum, exp);
}

如果我 运行 这个测试 ./boost_testing --log_level=all,我得到以下输出:

Running 2 test cases...
Entering test module "ExampleTestSuite"
boost_testing.cpp(11): Entering test suite "ExampleTest"
boost_testing.cpp(11): Entering test case "_0"
boost_testing.cpp(15): info: check testDatum == exp has passed
Assertion occurred in a following context:
    testDatum = 0;
boost_testing.cpp(11): Leaving test case "_0"
boost_testing.cpp(11): Entering test case "_1"
boost_testing.cpp(15): info: check testDatum == exp has passed
Assertion occurred in a following context:
    testDatum = 1;
boost_testing.cpp(11): Leaving test case "_1"
boost_testing.cpp(11): Leaving test suite "ExampleTest"
Leaving test module "ExampleTestSuite"

*** No errors detected

输出行Assertion occurred in a following context: testDatum = 0;是什么意思?它是否表明我设置数据驱动测试用例的方式存在问题,或者我可以安全地忽略它?

我同意该消息令人困惑:这实际上是测试断言上下文的描述 BOOST_CHECK_EQUAL(testDatum, exp),实际上这不是在描述错误,而是附加到检查的上下文。如果您将 --log_level=all 更改为其他内容,或使用其他输出格式,这应该会消失。

随时在 Boost.Test 项目

上提出问题