1、.pro文件增加QT += testlib

  QT工程文件qttest.pro

QT       += core testlib

TARGET = QTTest
CONFIG   += console

TEMPLATE = app

QMAKE_CXXFLAGS += --coverage
LIBS += -lgcov

DESTDIR += ./

SOURCES += main.cpp
           TestCase.cpp

HEADERS +=
           TestCase.h

INCLUDEPATH+= ./

  2、main.cpp 包含头文件#include<QtTest/QtTest>

  主程序main.cpp

#include <QtCore/QCoreApplication>
#include <QtTest/QtTest>
#include <QDebug>
#include "TestCase.h"

int main(int argc, char *argv[])
{
    qDebug() << "Test start";
    QCoreApplication a(argc, argv);

    CTestCase TestCase;
    QTest::qExec(&TestCase);

    qDebug() << "Test end";
    return 0;
}