2011-01-10 15 views
6

Patrząc na Qt's site, a na another Stackoverflow answer ponieważ nie chcę, aby utworzyć oddzielny projekt dla każdej klasy I chcesz przetestować, mam wymyślić następującego kodu:Running Qt Jednostka testuje

testqstring.h

#ifndef TESTQSTRING_H 
#define TESTQSTRING_H 

#include <QtTest/QTest> 

class TestQString : public QObject 
{ 
    Q_OBJECT 

private slots: 
    void toUpper(); 
}; 

#endif // TESTQSTRING_H 

testqstring.cpp

#include "testqstring.h" 
#include <QString> 

void TestQString::toUpper() 
{ 
    QString str = "Hello"; 
    QCOMPARE(str.toUpper(), QString("HELLO")); 
} 

main.cpp

#include "testqstring.h" 

int main(int argc, char *argv[]) 
{ 
    TestQString testqstring; 
    QTest::qExec(&testqstring, argc, argv); 
    return 0; 
} 

jednak otrzymuję następujące błędy linkera:

... 
g++ -headerpad_max_install_names -arch i386 -o tester main.o testqstring.o moc_testqstring.o -F/Library/Frameworks -L/Library/Frameworks -framework QtCore 
Undefined symbols: 
"QTest::qExec(QObject*, int, char**)", referenced from: 
_main in main.o 
"QTest::compare_helper(bool, char const*, char*, char*, char const*, char const*, char const*, int)", referenced from: 
bool QTest::qCompare<QString>(QString const&, QString const&, char const*, char const*, char const*, int)in testqstring.o 
... and more like that ... 

Co robię źle tutaj?

+1

Nie musisz łączyć z QTest? –

+0

@Noah co przez to rozumiesz? – wrongusername

Odpowiedz

10

Dodaj:

CONFIG += qtestlib 

do pliku .pro dostać qmake połączyć w qtest bibliotece.

+5

Lub obecnie: "QT + = testlib" – StellarVortex