I added an auto test project to my C++ Qt project (QT 5.15.1, MSVC 2019, host and target: Windows 10). But changes in the test source files do only take effect if I rebuild and run the test project, but not if I just build and run, which usually works fine for my main app project.
I guess I miss an important setting in my test project's .pro
file.
May somebody please tell me what I am missing?
I have the following project structure
/project
|- project.pro -- template = subdirs
|- /app
| |- app.pro -- template = app
| |- main.cpp
| \- mainwindow and source files
\- /tests
|- tests.pro -- template = subdirs
\- /unittests
|- unittests.pro -- template = subdirs
\- /objectXTest
|- objectXTest.pro -- template = app
|- tst_objectXTest.cpp
\- tst_objectXTest.h
where my objectXTest.pro
file is
QT += testlib
QT -= gui
SRC_DIR = ../../../app
INCLUDEPATH += \
$${SRC_DIR} \ # common/global project root headers
$${SRC_DIR}/path/to/objectX # headers relative to unit's source directory
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += \
tst_objectXTest.cpp \
$${SRC_DIR}/path/to/objectX/objectX.cpp
HEADERS += \
tst_objectXTest.h
and my test source is
// tst_objectXTest.h
#ifndef TST_OBJECTXTEST_H
#define TST_OBJECTXTEST_H
#include <QtTest>
// add necessary includes here
#include "objectX.h"
class ObjectXTest : public QObject {
Q_OBJECT
public:
ObjectXTest () {}
~ObjectXTest () {}
private slots:
void initTestCase();
void cleanupTestCase();
void test_construction();
};
#endif // TST_OBJECTXTEST_H
and
// tst_objectXTest.cpp
#include "tst_objectXTest.h"
void ObjectXTest::initTestCase() { }
void ObjectXTest::cleanupTestCase() { }
void ObjectXTest::test_construction() {
auto p_ox = new ObjectX();
QWARN("some message");
delete p_ox;
}
QTEST_APPLESS_MAIN(ObjectXTest)
I tried changing the message in QWARN
above, but re-executing will always print the text from last time re-building the test project.
I solved this myself, by the following steps (after making the above changes):
project.pro.user
file in the project root directoryproject.pro
Now a simple build does update files in the build directory partially to my changes and changes get effective immediately.