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

tow*_*owi 5 c++ boost boost-test c++14 c++17

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

我想知道是否有更多的C++ 14/C++ 17方式将BOOST_TEST_CASEs 组合在一起init_unit_test_suite

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

介绍:

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

using namespace boost::unit_test;
using namespace std::literals::string_literals;
Run Code Online (Sandbox Code Playgroud)

测试类:

class test_class {
public:
    void test_method1() {
        BOOST_CHECK( true /* test assertion */ );
    }
    void test_method2() {
        BOOST_CHECK( false /* test assertion */ );
    }
};
Run Code Online (Sandbox Code Playgroud)

建立套房:

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;
}
Run Code Online (Sandbox Code Playgroud)