使用 Boost::Test 测试 DLL? [英] Testing a DLL with Boost::Test?

查看:22
本文介绍了使用 Boost::Test 测试 DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 C++ 开发一个 DLL,并想使用 Boost 测试库对该 DLL 执行单元测试.我仔细阅读了 Boost 测试手册,但由于我是新手,我有以下问题:

I am developing a DLL in C++ and want to perform unit testing of that DLL using the Boost Test Libraries. I read the Boost test manual thoroughly but since I am new, I have the following question:

我应该在开发 DLL 的同一个 VC 项目中添加测试类吗?.理想情况下,我想这样做,但我很困惑 DLL 没有 main(),另一方面,Boost 测试需要自己的 main() 来执行.那么在这种情况下 Boost 测试输出去哪里了呢?(事实上​​,我实际上实现了这个并且没有看到任何输出:(并且几乎花了两天时间我才弄清楚问题,但没有成功)

Should I add test classes in the same VC project in which I am developing my DLL?. Ideally I want to do this but I am confused that a DLL has no main() and, on the other hand, the Boost test needs its own main() to execute. So where does the Boost test output go in this scenario? (In fact, I practically implemented this and don't see any output :( and almost spent two days I figuring out the problem, but didn't succeed)

问候,

詹姆.

推荐答案

您有 3 种方法可以做到这一点:

You have 3 ways to do this:

  1. 您绝对可以按照另一个回复的建议将您的库构建为静态库.不过我不推荐这种方式.

  1. You can definitely do what another reply suggest and build your lib as static. I wouldn't recommend this way though.

您的解决方案中可以有一个或多个单独的单元测试项目.这些项目将与您的库以及 Boost Test 库的静态或共享版本链接.每个项目都将有一个主要由 Boost.Test 库提供或由您手动实现.

You can have one or more separate unit test projects in your solution. These projects will link with your library and with either static or shared version of Boost Test library. Each project will have a main either supplied by the Boost.Test library or implemented by you manually.

最后,您还有另一个选择,您可以将测试用例直接放入库中.您需要链接到 Boost Test 的共享版本.构建库后,您可以像现在一样定期使用它,而且您将能够执行内置于其中的测试用例.要执行测试用例,您需要一个测试运行器.Boost Test 提供了一种称为控制台测试运行器"的工具.您只需要构建一次即可将其用于所有项目.使用此测试运行器,您可以像这样执行单元测试:

Finally you have another option and you can put your test cases directly into your library. You'll need to link with shared version of Boost Test. Once your library is built you can use it regularly as you do now plus you'll have an ability to execute test cases built into it. To execute the test case you'll need a test runner. Boost Test supplies one called "console test runner". You'll need to build it once and you can use for all your projects. Using this test runner you can execute your unit test like this:

test_runner.exe --test "your_lib".dll

test_runner.exe --test "your_lib".dll

您应该了解这种方法的所有优点和缺点.您的单元测试代码将成为您的生产库的一部分.它会使它稍微大一点,但另一方面,如果需要,您将能够在生产中运行测试.

You should understand all the pluses and minuses of this approach. Your unit test code will be part of your production library. It'll make it slightly bigger, but on the other hand you'll be able to run the test in production if necessary.

这篇关于使用 Boost::Test 测试 DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆