0

Using Boost.Test I'm trying to specify the BOOST_TESTS_TO_RUN environment variable in code, so that only some tests will be executed. Using #define BOOST_TESTS_TO_RUN.

The command line parameter --run_tests works fine. But I'd like to do it via the environment variable in order to have a single main.cpp in which I can select different suites and modules.

But I'm not sure on how to specify it, or where. Should it be before including boost? What if I have different cpp files with different test suites?

module_A.cpp

#include "SomeHeader.h"
#define BOOST_TESTS_TO_RUN // ??
#include "boost/test/unit_test.hpp"
BOOST_AUTO_TEST_SUITE( moduleA );
BOOST_AUTO_TEST_CASE( test1 ){}
BOOST_AUTO_TEST_CASE( test2 ){}
BOOST_AUTO_TEST_CASE( test3 ){}
BOOST_AUTO_TEST_SUITE_END();
Sergio Basurco
  • 3,488
  • 2
  • 22
  • 40

2 Answers2

0

The Boost UTF was not designed that way. If you really want to en-/disable certain tests from your code, you could use manual registration for all your tests and define a master test suite, in which you need to manually register all tests. See the master-test-suite documentation and other pages about manual test registration. You could then comment-out certain tests you don't want to run.

However, I do not recommend this approach. It's too easy to forget tests and thus harder to maintain. For debugging you could easily run the test executable by hand and use the command-line parameters.

Paul Omta
  • 1,703
  • 1
  • 12
  • 17
0

Check instead the new documentation of --run_test that explains that the environment variable BOOST_TEST_RUN_FILTERS can be used for that (also existing in the previous version of boost, but the environment variable usage is less obvious from the doc).

Basically, you compile your main.cpp only once with all tests (enabled by default) and then run them selectively from the BOOST_TEST_RUN_FILTERS environment variable.

I do not see a problem in doing this, especially wrt. the design of boost.test.

Raffi
  • 3,068
  • 31
  • 33