【问题标题】:Running Qt Unit tests运行 Qt 单元测试
【发布时间】:2011-01-10 02:16:14
【问题描述】:

查看Qt's siteanother 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*, 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 ...

我在这里做错了什么?

【问题讨论】:

  • 不需要链接QTest吗?
  • @Noah 你这是什么意思?

标签: c++ unit-testing qt4


【解决方案1】:

添加:

CONFIG += qtestlib 

到 .pro 文件以使 qmake 链接到 qtest 库中。

【讨论】:

  • 或者现在:“QT += testlib”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多