Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to use multiple test files for Boost unit test?

Reply
Thread Tools

How to use multiple test files for Boost unit test?

 
 
kathy
Guest
Posts: n/a
 
      08-02-2011
Right now I have 2 classes need to be tested. The files are:

MyMath.h / MyMath.cpp
MyHello.h / MyHello.cpp

I have written a test program for each of class:

HelloTest.cpp
-----------------------------
#include "MyHello.h"
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(HelloTests)
BOOST_AUTO_TEST_CASE (func_GetString_test)
{
MyHello h;
BOOST_CHECK_EQUAL(h.GetString(), std::string("Hello,
World!"));
}
BOOST_AUTO_TEST_SUITE_END()

MathTest.cpp
-----------------------------
#include "MyMath.h"
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(MyMathTests)
BOOST_AUTO_TEST_CASE (func_Add_test)
{
MyMath h;
BOOST_CHECK_EQUAL(h.Add(3, 2), 5);
}
BOOST_AUTO_TEST_SUITE_END()

Test_Runner.cpp
-----------------------------
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE MasterTestSuite
#include <boost/test/unit_test.hpp>

If I build the application, I got error:

boost_unit_test_framework-vc100-mt-1_47.lib(boost_unit_test_framework-
vc100-mt-1_47.dll) : error LNK2005: "public: static class
boost::unit_test::unit_test_log_t & __cdecl
boost::unit_test::singleton<class
boost::unit_test::unit_test_log_t>::instance(void) " (?instance@?
$singleton@Vunit_test_log_t@unit_test@boost@@@unit _test@boost@@SAAAVunit_test_log_t@23@XZ)
already defined in MyMath_test.obj
VCApp_Test.exe : fatal error LNK1169: one or more multiply defined
symbols found

But if I delete Test_Runner.cpp / MathTest.cpp files from project and
change "HelloTest.cpp" to:
-----------------------------
#include "MyHello.h"
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE MasterTestSuite
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(HelloTests)
BOOST_AUTO_TEST_CASE (func_GetString_test)
{
MyHello h;
BOOST_CHECK_EQUAL(h.GetString(), std::string("Hello,
World!"));
}
BOOST_AUTO_TEST_SUITE_END()

The application build OK and run OK.

So how to use multiple test files (1 file for each class) for Boost
unit test?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
contradicting unit test regarding blocks pass, bug in unit/test? timr Ruby 2 11-20-2010 06:30 AM
Boost unit test? carl C++ 3 12-01-2009 02:15 AM
Test::Unit -- multiple errors in test method ??? Johan Holmberg Ruby 7 09-15-2003 02:08 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57