Reputation: 3194
I have a Visual Studio
project where I want to do some unit tests with Boost.Test
.
And I have 2 files:
File 1:
#define BOOST_TEST_MODULE FileX
#include <boost/test/unit_test.hpp>
#include <stdio.h>
BOOST_AUTO_TEST_SUITE(test_suite_name)
BOOST_AUTO_TEST_CASE(TestFileX)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
And File 2:
#define BOOST_TEST_MODULE XContainer
#include <boost/test/unit_test.hpp>
#include <stdio.h>
BOOST_AUTO_TEST_SUITE(test_suite_name2)
BOOST_AUTO_TEST_CASE(TestXContainer)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
When I compile the project I get a link error that's saying that main is already defined.
I noticed that main
file is defined in unit_test.hpp
but I need to include it for the test macros.
How should I add 2 test cases in 2 separate file?
Upvotes: 4
Views: 3686
Reputation: 3356
testXXX.h shouldn't be included in testXXX.cpp.
All of testXXX.h files should be included in main.cpp which should contain #define BOOST_TEST_MODULE TestXXXXXXXXX
Upvotes: 0
Reputation: 2251
The real problem is that BOOST_TEST_MODULE is only ever intended to be defined once in your entire test executable. Defining BOOST_TEST_MODULE also defines BOOST_TEST_MAIN which pulls in an implementation of main.
So in one single place define BOOST_TEST_MODULE to be the name of your global suite and therefore also define BOOST_TEST_MAIN to get a single implementation of main.
This is a subtlety that I will need to note in my documentation rewrite.
Upvotes: 10
Reputation: 1734
You must use
#define BOOST_TEST_DYN_LINK
in every source file with tests.
Upvotes: 1