如何分辨如Boost.Test停止对第一失败的测试案例?(How to tell Boost.Tes

2019-07-29 02:20发布

我有一些在几个测试套件下令加速测试案例。 一些测试用例有一个,有一个以上的检查。

但是,在执行所有测试时,他们都得到执行 - 无论有多少失败或通过。 我知道,我可以用几个检查停止一个测试用例的执行BOOST_REQUIRE而不是BOOST_CHECK 。 但是,这不是要我要。

我怎么能告诉升压停止整个执行后的第一个测试用例失败了吗? 我宁愿在运行时解决方案编译解决方案(例如,与全球夹具实现)(即运行时参数)。

Answer 1:

BOOST_REQUIRE将停止在一个测试套件目前的测试案例,但去别人。

我实在不明白你想要什么,当你问一个“编译解决方案”,但这里的是,应该工作一招。 我用一个布尔值来检查整个测试套件的稳定性。 如果它是不稳定即BOOST_REQUIRE已被触发,则我停止了整个事情。

希望它可以帮助你。

//#include <...>

//FIXTURES ZONE
struct fixture
{
    fixture():x(0.0),y(0.0){}
    double x;
    double y;
};

//HELPERS ZONE
static bool test_suite_stable = true;

void in_strategy(bool & stable)
{
    if(stable)
        {
            stable = false;
        }
    else
        {
            exit();
        }
}

void out_strategy(bool & stable)
{
    if(!stable)
        {
            stable = true;
        }
}

BOOST_AUTO_TEST_SUITE(my_test_suite)

//TEST CASES ZONE
BOOST_FIXTURE_TEST_CASE(my_test_case, fixture)
{
    in_strategy(test_suite_stable);
    //...
    //BOOST_REQUIRE() -> triggered
    out_strategy(test_suite_stable);
}

BOOST_FIXTURE_TEST_CASE(another_test_case, fixture)
{
    in_strategy(test_suite_stable); //-> exit() since last triggered so stable = false
    //...
    //BOOST_REQUIRE()
    out_strategy(test_suite_stable);
}

BOOST_TEST_SUITE_END()

伯努瓦。



Answer 2:

为什么不直接使用断言? 你不仅立即中止整个程序,你也可以看到堆栈如果有必要。



文章来源: How to tell Boost.Test to stop on first failing test case?