我在我的 C++ Qt 项目(QT 5.15.1,MSVC 2019,主机和目标:Windows 10)中添加了一个自动测试项目。但是测试源文件中的更改只有在我重建并运行测试项目时才会生效,但如果我只是构建和运行则不会生效,这通常适用于我的主应用程序项目。
我想我错过了测试项目.pro
文件中的一个重要设置。
有人可以告诉我我错过了什么吗?
细节
我有以下项目结构
/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
我的objectXTest.pro
文件在哪里
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
我的测试源是
// 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
和
// 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)
我尝试更改QWARN
上面的消息,但重新执行将始终打印上次重新构建测试项目的文本。