提高数据驱动的测试输出:“断言在以下上下文中发生”

时间:2018-11-27 14:07:54

标签: c++ boost-test

我对以下使用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;是什么意思?它是否表明我设置了数据驱动的测试用例的方式存在问题,还是可以放心地忽略它?

1 个答案:

答案 0 :(得分:0)

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

随时在Boost.Test项目上提出问题