Take QtTestLib into use in a Qt project
What is the best and easiest way to integrate unit test library, QtTestLib, into existing Qt project with about 50 classes?
- Can I create for example 'test' folder under main project and put all test classes there including test application project file? How about including classes from existing project
- Do I have to copy from existing qt project file all the INCLUDES, LIBS, various CONFIGS into test application project file ?
Are there any example (large) projects where it is used?
Re: Take QtTestLib into use in a Qt project
Creating a test subdirectory is a very common approach.
Basicalyl rename your current main .pro file create a new one using template subdirs and putting the previous file as well as tests (name of the test subdirectory) into its SUBDIRS variable,
Or you restructure the project to have two (or more) subdirectories, one building the application.
For compiling, one option is to compile all needed classes into the test by adding them to the test's .pro file.
One other, usually more convenient, option is to put all classes into a static library and linking the main application and each test application against it.
If you need to share settings between the main application build and the test builds, put those into a .pri file (same syntax as .pro, basically a .pro include) and include it in each .pro file.
Cheers,
_
Re: Take QtTestLib into use in a Qt project
Quote:
Originally Posted by
anda_skoa
Creating a test subdirectory is a very common approach.
Basicalyl rename your current main .pro file create a new one using template subdirs and putting the previous file as well as tests (name of the test subdirectory) into its SUBDIRS variable,
Ok, this is the part I do not fully understand. I created new Qt Unit Test project with Qt Creator under 'test' directory.
QT += testlib
TARGET = tst_unittitestitest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += ../
SOURCES += tst_unittitestitest.cpp
DEFINES += SRCDIR=../
Should I add all the LIBS and INCLUDEPATH's from main application to this test.pro file. Is there easier way just to include all that is in main .pro file ?
It is very tedious to maintain two .pro files and have basically two copys of INCLUDEPATH's in two .pro files.
I know Qt is smarter than I think. So please help :)
Re: Take QtTestLib into use in a Qt project
Assuming ../ in your INCLUDEPATH refers to the top level directory of your project, then you can create a file like this (e.g. common.pri) in the top level directory
Code:
INCLUDEPATH += $$dirname(_FILE_)
LIBS #whatever you need
The all .pro files can simple include it. For example in your test
Code:
include(../common.pri)
Cheers,
_
Re: Take QtTestLib into use in a Qt project
Really having a problem here...
I'm still having a problem setting up a project with qttestlib. I get unresolved external symbols:
Code:
myclass.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyClass::metaObject(void)const " (?metaObject@MyClass@@UBEPBUQMetaObject@@XZ)
myclass.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyClass::qt_metacast(char const *)" (?qt_metacast@MyClass@@UAEPAXPBD@Z)
myclass.
obj : error LNK2001
: unresolved external symbol
"public: virtual int __thiscall MyClass::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyClass@@UAEHW4Call@
QMetaObject@@HPAPAX@Z
)debug\tst_testtest.exe : fatal error LNK1120: 3 unresolved externals
Here's my current project zipped.
http://phenoboy.kapsi.fi/App.zip
Thanks!
Re: Take QtTestLib into use in a Qt project
your tests.pro is missing the HEADERS line for the MyClass header
Cheers,
_
Re: Take QtTestLib into use in a Qt project
Quote:
Originally Posted by
anda_skoa
your tests.pro is missing the HEADERS line for the MyClass header
Cheers,
_
yes, it works thanks. Now I have to move SOURCES and HEADERS to own .pri file because I don't like to copy stuff to two places each time I add a new class in main project.