2016-06-29 15 views
1

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*' 

는 이해가 안 돼요. 재미있는 점은이 정확한 코드입니다 (전 꽤 확신합니다). 그러나 그 전에는 argcargvguiTest()에 잠시 전달하고 argcargv을 제거한 후 이전에했던 것 (내가 현재 가지고있는 것)으로 돌아갔습니다. 이 파일을 참조하십시오.)이 오류가 있습니다.

저는이 문제를 오랫동안 해결하려고 노력해 왔으며 온라인에서 답변을 찾을 수 없으므로 도움을 받으십시오. 도움을 받으시기 바랍니다. 감사!

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" 

답변

3
TestSuite1 testSuite1(); 

TestSuite1 복귀 testSuite1라는 함수를 선언한다. 주소를 가져 가면 TestSuite1* 대신 TestSuite1 (*)() (함수 포인터)가 제공되어 QObject*으로 변환됩니다.

를 사용하여 다음 중 하나를

TestSuite1 testSuite1; 
TestSuite1 testSuite1{}; 
auto testSuite1 = TestSuite(); 
auto testSuite1 = TestSuite{}; 

변수를 선언.

+1

아! 나는 이것이 그것이 바보 같을 것이라는 것을 알았다. 고마워요. – Dandido