Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

How to structure project while unit-testing Qt app by QTestLib

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.

  1. Can I put all source and testing code in same project? If so, how could I manage them? I didn't find any option that let me start app or start test in one project.
  2. If I put app source and testing code in separate projects, the testing project will reference app project, that's not quite convenient.
  3. For lots for classes required to be tested, how do I manage testing code?

How do you guys manage testing code in such a situation? Thanks.

question from:https://stackoverflow.com/questions/12154980/how-to-structure-project-while-unit-testing-qt-app-by-qtestlib

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...