如何写一个测试用例的qmake文件? [英] How to write the qmake file for a test case?

查看:203
本文介绍了如何写一个测试用例的qmake文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是不明白什么是一个程序和一个测试的Qt项目的总体布局...

I just don't understand what is the overall layout of a Qt project with a program and a test...

QTest教程的项目只有测试程序,但我的项目已经有另一个程序。如果我添加测试用例,它声称main()的多重定义,因为 QTEST_MAIN 实际上是另一个 main()

The project of QTest tutorial only have the test program, but my project already have another program. If I add the test case, it claims "multiple definition of main()", as QTEST_MAIN is actually another main().

另外,我在我的测试类中得到了未定义的vtable引用,不知道为什么。

In addition, I got "undefined reference to vtable" on my test class, and don't know why..

我使用Qt 5.2.1

I'm using Qt 5.2.1

这是我的项目文件:

#-------------------------------------------------
#
# Project created by QtCreator 2014-06-06T13:42:19
#
#-------------------------------------------------

QT       += core gui testlib
CONFIG += testcase

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = GutMiner
TEMPLATE = app
LIBS += -lquazip


SOURCES += main.cpp\
        mainwindow.cpp \
    dataform.cpp \
    datavec.cpp \
    distance.cpp \
    linereader.cpp \
    diseasepackage.cpp \
    error.cpp \
    newpagedialog.cpp \
    resultpage.cpp \
    test.cpp

HEADERS  += mainwindow.h \
    dataform.h \
    distance.h \
    datavec.h \
    linereader.h \
    diseasepackage.h \
    error.h \
    newpagedialog.h \
    resultpage.h

FORMS    += mainwindow.ui \
    dataform.ui \
    newpagedialog.ui

这是我的测试源文件:

#include <QObject>
#include <QTest>

#include "distance.h"
#include "diseasepackage.h"

class TestDistance: public QObject
{
    Q_OBJECT
public:
    virtual ~TestDistance();
private slots:
    void jensen_shannon();
};

TestDistance::~TestDistance() {}

void TestDistance::jensen_shannon()
{
    DiseasePackage pkg("CRC.zip");
}

QTEST_MAIN(TestDistance);


推荐答案

使用Qt 4.8)是有一个单独的.pro文件的测试程序。

One way to make this work properly (the one I use with Qt 4.8) is to have a separate .pro file for the test program.

主程序的.pro文件不包括测试代码。

The main program's .pro file does NOT include the test code.

QT       += core gui qt3support xml script

TARGET = simui
TEMPLATE = app

SOURCES += main.cpp\
    <lots of other source files

HEADERS  += \
    < header files>

FORMS    += \
    < form files > 

测试程序的.pro文件不包括main.cpp。测试程序的.pro文件包含测试库:

The test program's .pro file does NOT include main.cpp. The test programs's .pro file does include the test library:

QT      += core gui qt3support xml script
CONFIG  += qtestlib

TARGET = testsimui
TEMPLATE = app

SOURCES += \
    < all the sources form the main program (except main.cpp!) > 
    < all the test code sources. >

HEADERS += \
    < all the headers from the main program >
    < all the test code headers> 

FORMS    += \
    < all the forms from the main program > 

这不一定是最好的设置,但它可以很好地工作,将每个源文件添加到.pro文件。

This isn't necessarily the best setup, but it does work nicely, though you end up having to add each source file to both .pro file.

对于你的vtable问题,我不认为有足够的信息,你已经给出了什么。什么类有问题?此外,我很好奇为什么你有一个空析构函数在你的测试类。

As to your vtable problem, I don't think there's enough info in what you've given to make anything out of that. What class is having the problem? Also, I'm curious why you have an empty destructor on your test class.

这篇关于如何写一个测试用例的qmake文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆