[Boost-users] Boost.Test: How to create a multi-module (multi-file) test suite or how to link multiple auto test cases into one executable?

1,515 views
Skip to first unread message

Leonid Shlyapnikov

unread,
Feb 22, 2009, 10:55:06 AM2/22/09
to boost...@lists.boost.org
Hi everybody!

I got a bit rusty with C++. Can someone help me to understand how I
can create a Boost.Test suite that contains test cases from multiple
modules (multiple cpp files)?

Lets say I have:

file: ATest.cppp:
-----------------------------------------------------------------------
#define BOOST_TEST_MODULE ATest
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(testA1) {
....
}

BOOST_AUTO_TEST_CASE(testA2) {
....
}
-----------------------------------------------------------------------

file: BTest.cppp:
-----------------------------------------------------------------------
#define BOOST_TEST_MODULE BTest
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(testB1) {
....
}

BOOST_AUTO_TEST_CASE(testB2) {
....
}
-----------------------------------------------------------------------

Compilation passes all right. Linker gives:

In function `boost::unit_test::output::compiler_log_formatter::log_finish(std::basic_ostream<char,
std::char_traits<char> >&)':
/usr/include/c++/4.2/bits/char_traits.h:291: multiple definition of
`boost::unit_test::output::compiler_log_formatter::log_finish(std::basic_ostream<char,
std::char_traits<char> >&)'

I understand this error (even after 3-4 years of only Java :).

So, question: Is there any way to link multiple auto test cases into
one executable file? I have not found any information on this. Does it
mean that if I want to have one executable that runs all my test cases
I need to put/include all test case definitions into one cpp file?

Thanks a lot,
Leonid Shlyapnikov
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Gennadiy Rozental

unread,
Feb 22, 2009, 2:48:40 PM2/22/09
to boost...@lists.boost.org
Leonid Shlyapnikov <lshlyapnikov <at> gmail.com> writes:

> file: ATest.cppp:
> -----------------------------------------------------------------------
> #define BOOST_TEST_MODULE ATest

> file: BTest.cppp:
> -----------------------------------------------------------------------
> #define BOOST_TEST_MODULE BTest

1. BOOST_TEST_MODULE has to be defined once per test module, not once per test
file. This is the name of whte test module

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

2. You can't use single header variant of UTF and expect it to work in
multi-file case. You can read more about it in docs. You have t use once of the
library based usage variants.


Gennadiy

Reply all
Reply to author
Forward
0 new messages