开发者

Executing single Boost Test unit test in Visual Studio

开发者 https://www.devze.com 2023-04-12 13:07 出处:网络
I\'m trying to get unit testing set up with a c++ project using Visual Studi开发者_如何学Co and Boost Test. I\'ve read all questions on here and elsewhere on the internet about the combination, but al

I'm trying to get unit testing set up with a c++ project using Visual Studi开发者_如何学Co and Boost Test. I've read all questions on here and elsewhere on the internet about the combination, but although my question seems to be basic I don't find anything about it - so either I'm approaching it wrong or I'm just stupid.

I have a project xxx_test that tests the functionality in library xxx, also in its own project. What I want to do is set up a way to run all unit tests (which are grouped thematically in .cpp files) one by one, from the command line. But from what I understand, all unit tests are compiled into one big binary which is then run. Obviously I could set up a separate project for each .cpp file with tests, but that would leave me with dozens or hundreds of projects, each of which would depend on the xxx library project in the solution.

I guess what I want is a way to put all test .cpp files into one project, and then be able to select with a command-line switch to msbuild which single .cpp file to include in the project. Or is this not the way I should be doing it? Should I compile all tests each time I want to run them? What I want to do is be able to very quickly compile a test for a single object, so that I don't have to wait for everything to recompile on each run. Thanks.


Normally all unit tests are compiled into one big binary. However, you can run only one test from the command line using the runtime parameters.

For example, if you write two unit tests:

BOOST_AUTO_TEST_CASE( testA )
{
}

BOOST_AUTO_TEST_CASE( testB )
{
}

You may run only the first one using:

my_tests --run_test=testA

You may found some more usage examples here.

Programatically select the cpp to compile is a more difficult task. The solution may vary depending on your compilation time, number of test cpps, ...


Define a separate test suite in each test file and use --run=test_suite_name at runtime to select which one to test

0

精彩评论

暂无评论...
验证码 换一张
取 消