How to use multiple test files for Boost unit test?

K

kathy

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top