在 Visual Studio 中执行单个 Boost Test 单元测试

发布于 2024-12-09 14:41:48 字数 496 浏览 0 评论 0原文

我正在尝试使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

标点 2024-12-16 14:41:48

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

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

BOOST_AUTO_TEST_CASE( testA )
{
}

BOOST_AUTO_TEST_CASE( testB )
{
}

您可以使用以下命令仅运行第一个单元测试:

my_tests --run_test=testA

您可能会发现更多使用示例 此处

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

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

澜川若宁 2024-12-16 14:41:48

在每个测试文件中定义一个单独的测试套件,并在运行时使用 --run=test_suite_name 选择要测试的测试套件

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文