How to use multiple test files for Boost unit test?

Discussion in 'C++' started by kathy, Aug 2, 2011.

  1. kathy

    kathy Guest

    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?
    kathy, Aug 2, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VvanN
    Replies:
    5
    Views:
    476
    Phlip
    Apr 28, 2006
  2. Bill David
    Replies:
    2
    Views:
    261
    Arne Vajhøj
    Jun 18, 2008
  3. carl

    Boost unit test?

    carl, Nov 27, 2009, in forum: C++
    Replies:
    3
    Views:
    728
    Richard
    Dec 1, 2009
  4. Johan Holmberg
    Replies:
    7
    Views:
    156
    Johan Holmberg
    Sep 15, 2003
  5. timr
    Replies:
    2
    Views:
    152
Loading...

Share This Page