[英]Can I link multiple BOOST unit tests into a single test binary?
I've recently started trying to put a venerable and large (>1 million lines) program under test. 我最近开始尝试将一个令人尊敬的大型(> 100万行)程序进行测试。 There are currently no unit tests.
目前没有单元测试。 Also, the program is linked as each individual file being linked together - there are no component libraries.
此外,程序链接为每个单独的文件链接在一起 - 没有组件库。 Furthermore, the objects are highly interdependent, and it is difficult (impossible?) to link to any object files without linking to at least half of them.
此外,对象是高度相互依赖的,并且很难(不可能?)链接到任何目标文件而不链接到它们中的至少一半。
Yes, I know, my life sucks. 是的,我知道,我的生活很糟糕。
I'd like to do some refactoring (obviously), but I'd like to have some tests in place before I start moving things around. 我想做一些重构(显然),但我想在开始移动之前进行一些测试。 My current idea is to compile a single "test program" which runs all of the tests I create.
我目前的想法是编译一个单独的“测试程序”,它运行我创建的所有测试。 This would drastically simplify the linking issues that I have and let me focus on the real problems.
这将大大简化我的链接问题,让我专注于真正的问题。 So I have two questions:
所以我有两个问题:
I guess, this is precisely how to use boost test. 我猜,这正是如何使用升压测试。 I would keep one short main.cpp file consisting of literally 2 lines:
我会保留一个简短的main.cpp文件,由2行组成:
#define BOOST_TEST_MODULE "C++ Unit Tests for MyTangledLibrary"
#include <boost/test/included/unit_test.hpp>
And then I would keep adding test module *.cpp files compiled together into one executable 然后我会继续将编译在一起的测试模块* .cpp文件添加到一个可执行文件中
#include <boost/test/unit_test.hpp>
<< your include files >>
BOOST_AUTO_TEST_SUITE(FancyShmancyLogic)
BOOST_AUTO_TEST_CASE(TestingIf2x3equals6)
{
...
}
BOOST_AUTO_TEST_CASE(TestingIf2x2equals4)
{
...
}
BOOST_AUTO_TEST_SUITE_END()
Yes, you will be able to compile that main.cpp and all of your modules into one large executable. 是的,您将能够将main.cpp和所有模块编译为一个大型可执行文件。
An alternative approach follows from http://neyasystems.com/an-engineers-guide-to-unit-testing-cmake-and-boost-unit-tests/ , where you are not creating one single file, but still the enable_testing() in the cmake file allows you to call all tests at once with your generator. 另一种方法来自http://neyasystems.com/an-engineers-guide-to-unit-testing-cmake-and-boost-unit-tests/ ,您不是在那里创建一个文件,而是仍然使用enable_testing( )在cmake文件中,您可以使用生成器一次调用所有测试。 If your generator is make, then it's just make test.
如果您的发电机是制造的,那么它只是进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.