简体   繁体   中英

Qt Creator: unit-test: is it possible to have four ways of building a code (debug, release, debug|release and Test)

I am working with unit-test and I managed to create two projects in Qt-Creator: a unit-test project and Application project . Compiling both of them separately, I am very happy with both projects.

Then, I managed to link the two projects together, ie: testing a class ( myClass.cpp ) from my Application project using the unit-test project . the link was done by adding:

#INCLUDEPATH myApplicationProjectPath 
#SOURCES myApplicationProjectPath/myClass.cpp

to the .pro file of the unit-test project and everything is working fine and my unit test is functioning. (I am now building a lib instead of adding paths and classes).

In the meanwhile, in the .pro file of the Application project , I am having something like:

#CONFIG(debug, debug|release){
message(Debug bulid)
}

which is a conditional statement to whether compile the code in a Debug or debug|Relase modes.

taking into account that ( qmake processes a pro file up to three times depending on what the configuration is set to. Usually it will do it three times. Once for debug, once for release and one final one for debug_and_release.), what if I tried to use #CONFIG in my .pro file of the Application project to add a Test mode . so, when I try to build my project I will have the option to select whether to build in Test, debug or release mode.

doing so will allow me to avoid building separate project for unit-test and just add the classes I need to test within the #SOURCES section within the Test mode option.

so, is it possible to have four ways of building a code (debug, release, debug|release and Test) ?

Anything that is part of the CONFIG can be tested for as a scope for conditionals (see: QMake Configuration & Scope ). That means you can add your own meaning for "Test".

For Example

The following will add sources when "unittest" is added to the CONFIG using CONFIG += unittest

unittest {
    SOURCES += my_unittests.cc
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM