c++qtcppunit

Qt can't find files in a subproject


So, I'm trying to learn CppUnit testing. Since CppUnit needs it's own main function to run tests, I figured I would move my test suite into it's own sub-project. If that whole philosophy is wrong, please correct me. Then I will push this to my Git server and try to get the tests running in Jenkins on a Gerrit trigger. Ultimately, I'm trying to learn Jenkins and I'm creating a simple project to help me in that end. However, when I compile I get a lot of issues related to the files in JenkinsTestSuite not being able to find files in JenkinsTestMain. For example...

persontest.cpp:5:20: error: person.h: No such file or directory
In file included from persontest.cpp:7:

My (basic) directory structure is as such...

JenkinsTest |-JenkinsTestMain |-JenkinsTestSuite

My JenkinsTest.pro file looks like:

TEMPLATE = subdirs

SUBDIRS += \
    JenkinsTestSuite \
    JenkinsTestMain

CONFIG += ordered
SUBDIRS += JenkinsTestMain

My JenkinsTestMain.pro file looks like:

!include(../common.pri) {
    error(Couldn't find the common.pri file!)
}

QT       += core

QT       -= gui

TARGET = JenkinsTest
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp \
    person.cpp

HEADERS += \
        person.h

My JenkinsTestSuite.pro file looks like:

!include(../common.pri) {
    error(Couldn't find the common.pri file!)
}

QT       += core

QT       -= gui

TARGET = JenkinsTest
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

SOURCES += main.cpp \
    persontest.cpp \

HEADERS += \
    persontest.h

My common.pri file looks like:

INCLUDEPATH += . ..
WARNINGS += -Wall

TEMPLATE = lib

UI_DIR = .uics
MOC_DIR = .mocs
OBJECTS_DIR = .objs

Solution

  • JenkinsTestMain/ is not in the INCLUDEPATH, thus person.h is not found.

    In JenkinsTestSuite.pro, you must add

    INCLUDEPATH += ../JenkinsTestMain
    

    Alternatively, use #include in the test.

    I also suggest to add a DEPENDPATH += for each INCLUDEPATH +=, otherwise changes to person.h won't trigger persontest.cpp to be recompiled, which leads to wrong behaviour and crashes.

    Another issue here is that person.cpp is not part of JenkinsTest. You must either compile person.cpp another time for JenkinsTest, or put that code into a shared library.