我正在尝试使用 QtTest 为 c++ 应用程序创建测试。我拥有的三个相关文件是:GuiTests.cpp
其中包含我的主要功能,testsuite1.cpp
包含我的测试以及包含我的测试testsuite1.h
的定义。我在不同指南的帮助下创建了这些文件,例如这个.
当我尝试构建时,出现此错误:
no matching function for call to 'qExec(TestSuite1 (*)(), int&, char**&)'
no known conversion for argument 1 from 'TestSuite1 (*)()' to 'QObject*'
我不明白为什么,正如您在testsuite.h
下面看到TestSuite1
的那样QObject
。有趣的是这个确切的代码(我很确定)之前工作过,但后来我摆弄argc
了argv
一段guiTest()
时间,然后我删除argc
并argv
回到了我之前的状态(我目前拥有的,请参阅下面的文件)我收到了这个错误。
我一直在尝试解决这个问题很长时间,但我在网上找不到任何答案,所以请帮助我,感谢任何帮助。谢谢!
GuiTests.cpp
#include "testsuite1.h"
#include <QtTest>
#include <QCoreApplication>
int main(int argc, char** argv) {
TestSuite1 testSuite1();
return QTest::qExec(&testSuite1, argc, argv);
}
测试套件1.h
#ifndef TESTSUIT1_H
#define TESTSUIT1_H
#include <QMainWindow>
#include <QObject>
#include <QWidget>
#include <QtTest>
class TestSuite1 : public QObject {
Q_OBJECT
public:
TestSuite1();
~TestSuite1();
private slots:
// functions executed by QtTest before and after test suite
void initTestCase();
void cleanupTestCase();
// functions executed by QtTest before and after each test
//void init();
//void cleanup();
// test functions
void testSomething();
void guiTest();
};
#endif // TESTSUIT1_H
测试套件1.cpp
#include "testsuite1.h"
#include <QtWidgets>
#include <QtCore>
#include <QtTest>
TestSuite1::TestSuite1()
{
}
TestSuite1::~TestSuite1()
{
}
void TestSuite1::initTestCase()
{
}
void TestSuite1::cleanupTestCase()
{
}
void TestSuite1::guiTest()
{
QVERIFY(1+1 == 2);
}
void TestSuite1::testSomething()
{
QLineEdit lineEdit;
QTest::keyClicks(&lineEdit, "hello world");
QCOMPARE(lineEdit.text(), QString("hello world"));
//QVERIFY(1+1 == 2);
}
//QTEST_MAIN(TestSuite1)
//#include "TestSuite1.moc"