I got my Qt project and I'm using Qt Creator. I want to unit-test all my code.
However I'm quite new at QTestLib framework but everyone recommended it for testing Qt-based source. Now I'm a little confused how to structure test project with app project.
How do you guys manage testing code in such a situation? Thanks.
Writing a Test First, you need a class that contains your test functions. This class has to inherit from QObject: #include <QTest> class TestQString: public QObject { Q_OBJECT private slots: void toUpper(); };
First structure source like below:
MyApp MyAppUnitTest
Under MyApp
project, use a MyAppSrc.pri
to locate source files:
SOURCES += \ ../../../framework/src/myapp.cpp \ ../../../framework/src/mycontrol.cpp HEADERS += \ ../../../framework/inc/myapp.h \ ../../../framework/inc/mycontrol.h INCLUDEPATH += ../../../framework/extlibs
Include this .pri
in MyApp.pro
like:
include(MyAppSrc.pri)
Then structure the testing project exactly like the main project, with one extra include in MyAppUnitTest.pro
:
include(MyAppUnitTestSrc.pri) include(../MyApp/MyAppSrc.pri)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With