0
我有一個非常糟糕的gui應用程序類Tools()。我想用單元測試在同一個文件中測試其他類的Tree()。qt單元測試QTreeWidgetItem尚未聲明
我寫了簡單的空樹類來嘗試單元測試。
的Tools.h
#ifndef TOOLS_H
#define TOOLS_H
#include "json.h"
#include <QString>
#include <QList>
#include <QSettings>
...
class Tools
{
public:
Tools();
static void createTree(Json::Value parsedJSON, treeElement *Element);
static void reloadTree(QTreeWidgetItem *item, treeElement *Element);
....
static QMap<QString, QString> Dictionary;
};
class Tree
{
public:
Tree();
};
#endif // TOOLS_H
大多數代碼在由QT自動生成該文件。我只寫了isCreatable()。
當測試項目開始時,this erorrs出現了。 我不知道它爲什麼不編譯,但我想一些定義,幷包括錯誤。
TREE_TEST.cpp
#include <QString>
#include <QtTest>
#include "tools.h"
class TreeTest : public QObject
{
Q_OBJECT
public:
TreeTest();
private Q_SLOTS:
void isCreatable();
};
TreeTest::TreeTest()
{
}
void TreeTest::isCreatable()
{
Tree *newTree = NULL;
QVERIFY2(newTree == NULL, "Can't create empty Tree");
newTree = new Tree();
QVERIFY2(newTree != NULL, "Can't create new instance of Tree");
}
QTEST_APPLESS_MAIN(TreeTest)
#include "tst_treetest.moc"
這是我的測試親文件。我包括測試項目的路徑和依賴關係(只是簡單的json解析庫)。
TREE_TEST.pro
#-------------------------------------------------
#
# Project created by QtCreator 2015-09-06T20:42:18
#
#-------------------------------------------------
QT += testlib gui
TARGET = tst_treetest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += ../../dependencies/json
INCLUDEPATH += ../../
SOURCES += tst_treetest.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
請幫助我認識和解決這個煩惱。我不明白,出了什麼問題......
P.S.我的英文不是很好。請容忍。
#include? –
Chernobyl
不完全。 當我這樣做時,「Qtreewidget項目沒有這樣的文件或目錄」出現了。 我搜索的stackoverflow和找到http://stackoverflow.com/questions/16791844/error-qt-5-0-qtreewidget-include-not-found 它說:添加到你.pro文件QT + =部件 – gek0n