在Visual Studio中执行单个Boost测试单元测试(Executing single Boost Test unit test in Visual Studio)

编程入门 行业动态 更新时间:2024-10-28 14:32:05
在Visual Studio中执行单个Boost测试单元测试(Executing single Boost Test unit test in Visual Studio)

我正在尝试使用Visual Studio和Boost Test在c ++项目中设置单元测试。 我已经在网上和其他地方读过关于这个组合的所有问题,但是虽然我的问题似乎是基本的,但我找不到任何关于它的东西 - 所以要么我接近错了,要么我只是愚蠢。

我有一个项目xxx_test,它测试库xxx中的功能,也在它自己的项目中。 我想要做的是设置一种方法,从命令行逐个运行所有单元测试(主题在.cpp文件中分组)。 但据我所知,所有单元测试都编译成一个大的二进制文件然后运行。 显然,我可以为每个带有测试的.cpp文件设置一个单独的项目,但这会让我有数十个或数百个项目,每个项目都取决于解决方案中的xxx库项目。

我想我想要的是一种将所有测试.cpp文件放入一个项目的方法,然后能够通过命令行切换到msbuild选择要包含在项目中的单个.cpp文件。 或者这不是我应该这样做的方式吗? 我应该每次运行它们时编译所有测试吗? 我想要做的是能够非常快速地编译单个对象的测试,这样我就不必等待每次运行时重新编译所有内容。 谢谢。

I'm trying to get unit testing set up with a c++ project using Visual Studio 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.

最满意答案

通常,所有单元测试都编译成一个大的二进制文件。 但是,您只能使用运行时参数从命令行运行一个测试。

例如,如果您编写两个单元测试:

BOOST_AUTO_TEST_CASE( testA ) { } BOOST_AUTO_TEST_CASE( testB ) { }

您可以使用以下方式仅运行第一个:

my_tests --run_test=testA

您可以在此处找到更多用法示例。

以编程方式选择cpp进行编译是一项比较困难的任务。 解决方案可能会有所不同,具体取决于您的编译时间,测试cpps数量,......

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, ...

更多推荐

本文发布于:2023-08-07 19:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465684.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   测试   Studio   Boost   Visual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!