How to set which Boost unit test to run

白昼怎懂夜的黑 提交于 2019-12-12 13:17:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5103886/how-to-set-which-boost-unit-test-to-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!