使用boost为测试类实现测试套件构建器的现代方法是什么?

时间:2016-08-21 18:47:45

标签: c++ boost c++14 c++17 boost-test

Boost.Test 文档中的示例似乎主要是指C ++ 03代码。

我想知道是否有更多的C ++ 14 / C ++ 17方式将BOOST_TEST_CASE放在init_unit_test_suite中?

这是我从文档中获得的。我只用lambdas交换boost::bind。我想不出那个代码的任何进一步“现代化”。有人可以吗?

说明:

#include <boost/test/included/unit_test.hpp>
#include <memory> // shared ptr

using namespace boost::unit_test;
using namespace std::literals::string_literals;

测试类:

class test_class {
public:
    void test_method1() {
        BOOST_CHECK( true /* test assertion */ );
    }
    void test_method2() {
        BOOST_CHECK( false /* test assertion */ );
    }
};

构建套件:

test_suite*
init_unit_test_suite( int argc, char* argv[] )
{
    auto tester = std::make_shared<test_class>();
    auto &ts = framework::master_test_suite();
    ts.add( BOOST_TEST_CASE( [=](){ tester->test_method1(); } ));
    ts.add( BOOST_TEST_CASE( [=](){ tester->test_method2(); } ));
    return nullptr;
}

0 个答案:

没有答案
相关问题