升压单元测试框架,动态链接和手动设置 [英] Boost unittest framework with dynamic linking and manual setup

查看:114
本文介绍了升压单元测试框架,动态链接和手动设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个升压单元测试与动态链接和手动设置(不BOOST_AUTO_TEST_CASE)框架。我做了一个简单的例子来重现我的错误:

I am trying to setup a boost unittest framework with dynamic linking and manual setup (Not BOOST_AUTO_TEST_CASE). I have made a trivial example to reproduce my errors:

//SomeLib.cpp
#define BOOST_TEST_DYN_LINK
#include "SomeLib.h"
int getImportantNumber(){return 1729;}
int increaseNumber(int number){return number+1;}

//SomeTests.cpp
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "lib/SomeLib.h"
#include "SomeTests.h"
using namespace boost::unit_test;

void SomeTests::numberIs1729(){
    BOOST_CHECK(getImportantNumber() == 1729);
}
void SomeTests::increase(){
    BOOST_CHECK(increaseNumber(1) == 2);
}

//ChainedInc.cpp
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "lib/SomeLib.h"
#include "ChainedInc.h"
using namespace boost::unit_test;

void ChainedInc::incinc(){
    BOOST_CHECK(increaseNumber(increaseNumber(1)) == 3);
}
void ChainedInc::incincinc(){
    BOOST_CHECK(increaseNumber(increaseNumber(increaseNumber(1))) == 4);
}

//Master.cpp
#define BOOST_TEST_DYN_LINK
#include <boost/bind.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/test/unit_test.hpp>
#include "SomeTests.h"

using namespace boost::unit_test;
test_suite* init_unit_test_suite( int, char** )
{
    test_suite* ts1 = BOOST_TEST_SUITE( "Suite1" );

    boost::shared_ptr<SomeTests> test1 ( new SomeTests());
    ts1->add( BOOST_TEST_CASE( boost::bind(&SomeTests::numberIs1729, test1)));
    ts1->add( BOOST_TEST_CASE( boost::bind(&SomeTests::increase, test1)));

    framework::master_test_suite().add( ts1 );
    return 0;
}

当我运行这个code我得到以下错误:

When I run this code I get the following error:

/usr/bin/g++ test/ChainedInc.cpp.1.o test/Master.cpp.1.o test/SomeTests.cpp.1.o lib/SomeLib.cpp.2.o -o /home/mto/src/manualBoost/build/test/app -Wl-Bdynamic -L/usr/lib64 -lboost_unit_test_framework

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

这通常是由于添加解决

#define BOOST_TEST_DYN_LINK

所有的测试文件以及

to all test files and

#define BOOST_TEST_MODULE something

准确任意一个测试文件。然而,最后确定时,升压试验手动注册不能很好地工作。如果我尝试使用后,运行我的测试这个定义,我得到

to exactly one arbitrary test file. However the last define does not work well when the boost tests are registered manually. If I try to run my tests after using this define I get

build/test/app

Test setup error: test tree is empty

请参阅加速测试不init_unit_test_suite 。是否有可能用提高对提振手工登记和动态链接?

See Boost test does not init_unit_test_suite. Is it possible to use boost manual registration and dynamic linking against boost?

推荐答案

我设法测试的手动设置与动态链接共同努力,积极促进当我用标题中只能库。

I managed to get Manual setup of test to work with dynamic linking to boost when I used the header only libraries.

-#include <boost/test/unit_test.hpp>
+#include <boost/test/included/unit_test.hpp>

这篇关于升压单元测试框架,动态链接和手动设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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