QtTest を使用して C++ アプリケーションのテストを作成しようとしています。私が持っている3つの関連ファイルは次のとおりです。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
andargv
を渡していじり、 and を削除した後、以前のものに戻りました (現在持っているものについては、を参照してください)以下のファイル) このエラーが発生しました。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);
}
testsuite1.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
testsuite1.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"