C++ 单独cpp文件中的Boost单元测试
我想将Boost单元测试分离到单独的.cpp文件中,例如Test1.cpp、Test2.cpp、Test3.cpp。。。等,这样我就不会在一个cpp文件中有1000个测试。到目前为止,我在尝试构建时遇到了各种各样的错误 Test1.cppC++ 单独cpp文件中的Boost单元测试,c++,unit-testing,boost,boost-test,C++,Unit Testing,Boost,Boost Test,我想将Boost单元测试分离到单独的.cpp文件中,例如Test1.cpp、Test2.cpp、Test3.cpp。。。等,这样我就不会在一个cpp文件中有1000个测试。到目前为止,我在尝试构建时遇到了各种各样的错误 Test1.cpp #define BOOST_TEST_MODULE MasterTestSuite #include <boost/test/included/unit_test.hpp> BOOST_AUTO_TEST_CASE(myTestCase) {
#define BOOST_TEST_MODULE MasterTestSuite
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(myTestCase)
{
BOOST_CHECK(1 == 1);
}
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(MyTests)
BOOST_AUTO_TEST_CASE(myTestCase)
{
BOOST_CHECK(1 == 1);
}
BOOST_AUTO_TEST_SUITE_END()
Test2.cpp
#define BOOST_TEST_MODULE MasterTestSuite2
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(myTestCase2)
{
BOOST_CHECK(2 == 2);
}
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(MyTests2)
BOOST_AUTO_TEST_CASE(myTestCase2)
{
BOOST_CHECK(2 == 2);
}
BOOST_AUTO_TEST_SUITE_END()
定义boost_test_模块时,boost test会生成自己的主函数,请参见:。你的一些错误很可能就是因为这个
我将BOOST_TEST_模块放在一个单独的文件中,例如:
test_main.cpp
#ifndef _MSC_VER
#define BOOST_TEST_DYN_LINK
#endif
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE Main
#include <boost/test/unit_test.hpp>
Test2.cpp
#define BOOST_TEST_MODULE MasterTestSuite2
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(myTestCase2)
{
BOOST_CHECK(2 == 2);
}
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(MyTests2)
BOOST_AUTO_TEST_CASE(myTestCase2)
{
BOOST_CHECK(2 == 2);
}
BOOST_AUTO_TEST_SUITE_END()
您可以在tests目录中找到这种方法的示例。到目前为止,我在尝试构建时遇到了各种各样的错误。-你能给我们举个例子吗?请将其编辑为以下问题:BOOST_TEST_模块对于单个二进制文件只应定义一次,文档的第二部分说明了如何使用多个翻译单元的仅标题方法。