[SOLVED] Linking Unit Test to MyProject
I'm trying to make an Unit Test (using CppUnit) for MyProject.
I will describe the situation first.
I made 2 separated projects: MyProject and UnitTestProject.
The hierarchy looks like this:
unittestproject.pro looks like this:
@QT += testlib
QT -= gui
TARGET = tst_unittestproject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
unix|win32: LIBS += -lcppunit@
In heatingonoffcontroller.h is a class named HeatingOnOffController
In ut_heatingonoff.h I made a class like this:
class utHeatingOnOffController : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(utHeatingOnOffController); CPPUNIT_TEST(testTestTest); CPPUNIT_TEST_SUITE_END();
In ut_heatingonoffcontroller.cpp I made an implementation like this:
using namespace CppUnit;
using namespace std;
TestObjectHeatingOnOffController = new HeatingOnOffController(NULL,0,0);
The strange thing is that QtCreator recognizes HeatingOnOffController, but gives an error at this line:
@TestObjectHeatingOnOffController = new HeatingOnOffController(NULL,0,0);@
I get the following error:
In function 'void utHeatingOnOffController::setUp(void)':
undefined reference to 'HeatingOnOffController::HeatingOnOffController(QObject*,int,int)'
collect2: error: Id returned 1 exit status
I think it has something to do with the link between the 2 projects, but I don't know how to do that correct in the .pro files.
Does anybody know what I'm doing wrong? I'm struggling with it for days!
You don't link your unit test to your MyProject library
thanks for the reaction!
That's what I thought, but how do I do that?
Qt is kind of new to me.
Btw: Is it an option for me to create an library file of MyProject and include that in UnitTestProject.pro?
Use the lib template and in your unit test add
and you should be good