QtTestを使用してC++アプリケーションのテストを作成しようとしています。私が持っている3つの関連ファイルは:GuiTests.cpp
私の主な機能、私のテストを含むtestsuite1.cpp
と私のテストの定義を含むtestsuite1.h
が含まれています。さまざまなガイドの助けを借りてこれらのファイルを作成しました。たとえば、this oneです。qExecを呼び出すときにエラーが発生しました。「引数1のQObjectへの既知の変換がありません」
私が構築しようとした際、私はこのエラーを取得:
no matching function for call to 'qExec(TestSuite1 (*)(), int&, char**&)'
no known conversion for argument 1 from 'TestSuite1 (*)()' to 'QObject*'
あなたはTestSuite1
の下testsuite.h
に見ることができるように私は、理由を理解していないが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);
}
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"
Ah!私はそれがこのような愚かなものになるだろうと分かっていました。ありがとう、たくさんの友達! – Dandido