如何设置运行哪个Boost单元测试 [英] How to set which Boost unit test to run
问题描述
我正在尝试使用增强测试,尤其是增强单元测试.
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.
推荐答案
最简单的方法是将测试写入一个.cpp
文件,并在包含unit_test.hpp
之前定义宏BOOST_TEST_MODULE
.然后,您可以编译该.cpp
文件并执行它.如果您在多个.cpp
文件中进行了测试,只需将它们链接在一起,但要确保在其中一个中完全定义了BOOST_TEST_MODULE
或BOOST_TEST_MAIN
.
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.
这篇关于如何设置运行哪个Boost单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!