我在我的C++ Qt项目中添加了一个自动测试项目(QT5.15.1,MSVC2019,主机和目标: 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中更改消息,但是重新执行总是会打印上次重新构建测试项目时的文本。
发布于 2021-01-12 08:13:23
我自己解决了这个问题,通过以下步骤(在进行了上述更改之后):
删除项目根directory
project.pro上执行qmake
现在,一个简单的构建确实会将构建目录中的文件部分更新到我的更改中,并且更改会立即生效。
https://stackoverflow.com/questions/65668961
复制相似问题