我正在尝试为我在 QT 中的每个类创建一个新的测试类。我有这个使用单个文件,但这依赖于 QTEST_MAIN 为我创建一个应用程序并在多个文件中调用它会创建一个多重定义错误。
我曾尝试自己创建一个 main(),然后运行一个 qExec,但没有成功。我正在使用 SCONS 进行构建,但没有找到任何资源可以在该构建系统中进行该工作。
这是我最近失败的尝试:
#include <QtTest/QtTest>
#include "path/test1.h"
#include "path/test2.h"
class TestMain : public QObject {
Q_OBJECT
private:
TEST1 test1;
TEST2 test2;
private Q_SLOTS:
void initTestCase();
};
void TestMain::initTestCase(){
//these are causing multiple def of main
test1.initTestCase();//these only have data to setup the UI to test on
test2.initTestCase();//these only have data to setup the UI to test on
}
QTEST_MAIN(TestMain);
有没有一种干净的方法可以在不使用 QTEST_MAIN 宏的情况下实现这样的事情,或者使用它来调用单个插槽,然后从单独的类中收集所有测试?
我发现的所有其他解决方案都创建了一个新的主要解决方案,我宁愿不这样做,因为它会产生更多设置问题,例如创建一个必须接受所有类和重复代码的部分的 QApplication。