peter55555
peter55555

Reputation: 1475

Boost test - every suite in other file

I have file test.cpp. It looks like this:

#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>


BOOST_AUTO_TEST_SUITE( test_suite1 )

BOOST_AUTO_TEST_CASE( my_test )
{
    // testing...
}

BOOST_AUTO_TEST_SUITE_END()

It's OK. It works....

But I want to have more BOOST_AUTO_TEST_SUITE and I'd like to have every suite in other file.

I'd like to run all test cases from every test suite. What should I do?

Upvotes: 2

Views: 1238

Answers (1)

TemplateRex
TemplateRex

Reputation: 70526

I have a similar setup to what you want (see this Q&A). If you want a CMake solution, look there. Otherwise, simply split your test cases over several files and compile and link each of them separately with the options

 -DBOOST_TEST_MAIN -DBOOST_TEST_DYN_LINK

Note: it's generally preferred to put the macros as compiler/linker options rather than inside your source files. With several test sources and a CMake build solution, you can then call ctest to run all tests executables.

If you want one test executable, them compile each of the test separately, and link them together into one executable. Then you can run this executable and it will run all tests. Note however that it is a lot more difficult to run only a selection of your tests this way.

Upvotes: 1

Related Questions