3

I am trying to use boost-test, and in particular boost unit testing.

I clearly don't understand how is the main function generated and called, all the tutorial says is to define a module and write a test

#define BOOST_TEST_MODULE EnfTraderTest

BOOST_AUTO_TEST_CASE(CalculateExpectedPriceTest){BOOST_ERROR("Oops");}

But, how do I say to my program to run this test ? I already have main function, I would like to decide to run the test or not, from my main function.

0x26res
  • 11,925
  • 11
  • 54
  • 108
  • Duplicate of http://stackoverflow.com/q/963158/232490? – Xepo Mar 07 '11 at 04:33
  • Possible duplicate of [How to execute test suites based on requirement in boost.test library](http://stackoverflow.com/questions/3615979/how-to-execute-test-suites-based-on-requirement-in-boost-test-library) – Jørgen Fogh Nov 03 '15 at 15:34

1 Answers1

5

The simplest way to do this is to write your tests into one .cpp-file, and define the macro BOOST_TEST_MODULE before you include unit_test.hpp. You can then compile that .cpp-file and execute it. If you have tests in several .cpp-files, just link them all together, but take care that either BOOST_TEST_MODULE or BOOST_TEST_MAIN are defined in exactly one of them.

You can use the command-line parameter run_test to only run a subset of tests, the default is to run all tests.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
  • 3
    A note on `run_test`: if you use wildcards (e.g. `--run_test=*foo*`), depending on your shell, you may need to escape the wilcards (e.g. `--run_test=\*foo\*`). That just happened to me with `zsh`. – BenC May 15 '15 at 02:46