PDA

View Full Version : qmake project setup - qtestlib scenario



dsaiko
3rd April 2009, 08:05
Hello all,

I am trying to setup some structured generic project skeleton and running into a problem separating qtlibtest into subproject, as those should not be built in as part of the application, and I am trying to use some structured project setup as I do not like all files just being in one folder (I am in general a Java developer).. I have spent a half day searching the internet have not found anything. :confused:

sampleapp-project.pro:
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = sampleapp sampleapp-tests

sampleapp.pro
TEMPLATE = app
TARGET =
DEPENDPATH += . inc src
INCLUDEPATH += . inc src
HEADERS += painter.h
SOURCES += painter.cpp main.cpp

sampleapp-tests.pro
TEMPLATE = app
QT += testlib
TARGET =
DEPENDPATH += . inc src ../sampleapp/inc ../sampleapp/src
INCLUDEPATH += . inc src ../sampleapp/inc ../sampleapp/src

# Input
HEADERS += sampleapp-tests.h
SOURCES += sampleapp-tests.cpp

There exist painter.h and painter.cpp defining Painter object under sampleapp project.

My problem is trying to use this Painter object from class PainterTest which is under sampleapp-tests project, receiving "undefinied reference to 'Painter:Painter()' when building.

If I look at the compile output, the test is not linking against objects from the sampleapp:

g++ -o sampleapp-tests debug/sampleapp.o debug/moc_sampleapp.o -L/usr/lib -lQtTest -lQtGui -lQtCore -lpthread

I very appreciate any help on:

- how to make this scenario work
- is this the way project should be setup, are there any guidlines and may be tutorials on this ?

thank you in advance

Loremo
6th June 2011, 15:52
Hello,

i have the same problem.

I found a "workaround" how it works:

If you build the sampleapp as a library:
sampleapp.pro:

TEMPLATE = lib
TARGET = lib
DEPENDPATH += . inc src
INCLUDEPATH += . inc src
HEADERS += painter.h
SOURCES += painter.cpp #without main.cpp
and then change sampleapp-tests.pro to:

TEMPLATE = app
QT += testlib
TARGET =
LIBS += lib.so # built by sampleapp
DEPENDPATH += . inc src ../sampleapp/inc ../sampleapp/src
INCLUDEPATH += . inc src ../sampleapp/inc ../sampleapp/src

# Input
HEADERS += sampleapp-tests.h
SOURCES += sampleapp-tests.cpp
It works this way! But does it mean that i only can do unit testing with libraries? how can i test projects which were built as TEMPLATE = app?

Or: does it mean that my unit testing classes have to in the same project as my classes that i want to test? Is there a way i can have:

MyPrject
|---Core # TARGET = app
| |--core.h
| |--core.cpp
|---CoreTest # tests the core-class
|--main.cpp
?
Need help, thank you in advice.