The examples in the documentation of Boost.Test seem to be mostly refering to C++03 code.
I wonder if there is a more C++14/C++17-way of putting together the BOOST_TEST_CASE
s in init_unit_test_suite
?
This is what I derived from the documentation. I only exchanged boost::bind
with lambdas. I can not think of any further "modernization" of that code. Can anyone?
Intro:
#include <boost/test/included/unit_test.hpp>
#include <memory> // shared ptr
using namespace boost::unit_test;
using namespace std::literals::string_literals;
Test class:
class test_class {
public:
void test_method1() {
BOOST_CHECK( true /* test assertion */ );
}
void test_method2() {
BOOST_CHECK( false /* test assertion */ );
}
};
Building the suite:
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;
}