查看
Qt’s site和
another Stackoverflow answer,因为我不想为每个要测试的类创建一个单独的项目,我想出了以下代码:
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; }
... 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*,int)",referenced from: bool QTest::qCompare<QString>(QString const&,QString const&,int)in testqstring.o ... and more like that ...
我在这做错了什么?