I'm adding boost unit test to an already working eclipse project with the well known pure virtual Shape class and a derived Circle class. I'm able to calculate radius, perimeter, area etc., nothing spectacular.
If the answer is obvious I have moved my question to the top so you don't have to read through what works and what doesn't. It was originally at the bottom.
Do I need two separate eclipse-projects, one with the tests, and one with the release/debug builds?
I have added C/C++ Unit Testing Support in eclipse (mars edition) on os x and installed boost test via macports. I followed the advise having a separate folder for test as given here.
I have excluded the test-folder from the release build process and have excluded the project-folder from debug-build ditto. I have also added the source folder as Include path in Settings for the test-folder and added test framework library. Running a simpel test works.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Fixtures
#include <boost/test/unit_test.hpp>
#include "Circle.hpp"
int add(int i, int j)
{
return i + j;
}
BOOST_AUTO_TEST_CASE(equal)
{
BOOST_CHECK(add(2, 2) == 4);
}
The test example is from here. Trying to compile with the Circle-class fails. Autocomplete works so it pulls the header file into the test-folder.
BOOST_AUTO_TEST_CASE(shape)
{
gnome::Circle c1;
}
The error is
Undefined symbols for architecture x86_64:
"gnome::Circle::Circle()", referenced from:
shape::test_method() in test_main.o
"gnome::Circle::~Circle()", referenced from:
shape::test_method() in test_main.o
ld: symbol(s) not found for architecture x86_64
and the solution would be to add the object files from the build phase but I don't have the C++ Linker option in Properties->C/C++ Build->Settings for the test-folder, only for the project-folder.
This SO answer indicates to code first and then add tests. But that defeats the purpose of unit testing.
Aucun commentaire:
Enregistrer un commentaire