QtTest를 사용하여 C++ 응용 프로그램에 대한 테스트를 만들려고합니다. 내가 가지고있는 세 가지 관련 파일은 다음과 같습니다. GuiTests.cpp
에는 내 테스트가 포함 된 testsuite1.cpp
과 내 테스트의 정의가 포함 된 testsuite1.h
이 있습니다. 다른 가이드의 도움으로이 파일을 만들었습니다 (예 : this one). qExec를 호출 할 때 오류가 발생했습니다. "QObject에 인수 1에 대한 알려진 변환이 없습니다."
나는이 오류가 구축하려고
하십시오QObject
왜, 당신이
TestSuite1
아래
testsuite.h
에서 볼 수
no matching function for call to 'qExec(TestSuite1 (*)(), int&, char**&)'
no known conversion for argument 1 from 'TestSuite1 (*)()' to '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"
아! 나는 이것이 그것이 바보 같을 것이라는 것을 알았다. 고마워요. – Dandido