QtTestLib Introduction

#include <QtCore/QString>
#include <QtTest/QtTest>
#include "timeconversion.h"

class TimeConversionTest : public QObject
{
    Q_OBJECT

public:
    TimeConversionTest();

private Q_SLOTS:
    void initTestCase();
    void cleanupTestCase();
    void testCase1();
    void testCase1_data();

    void testCase2();
    void testCase2_data();

    void init();
    void cleanup();
};

TimeConversionTest::TimeConversionTest()
{
}

void TimeConversionTest::init()
{
    qDebug() << "init is called before EVERY test function";
}

void TimeConversionTest::cleanup()
{
    qDebug() << "cleanup is called AFTER every test function";
}

void TimeConversionTest::initTestCase()
{
    qDebug() << "initTestCase is called at the start of the test case (once per program)";
}

void TimeConversionTest::cleanupTestCase()
{
    qDebug() << "cleanupTestCase is called at the end of the test case (once per program)";
}

void TimeConversionTest::testCase1()
{
    QFETCH(QString, data);
    QVERIFY2(true, "Failure");
}

void TimeConversionTest::testCase2()
{
    TimeConversion c;
    QVERIFY2(c.hrsToSeconds(1) == 3601, "One Hour");
}

void TimeConversionTest::testCase1_data()
{
    QTest::addColumn<QString>("data");
    QTest::newRow("0") << QString();
}

void TimeConversionTest::testCase2_data()
{
    QTest::addColumn<QString>("data");

    QTest::newRow("0") << QString("Foo1");
    QTest::newRow("1") << QString("Bar1");
    QTest::newRow("2") << QString("Buz");
}

QTEST_APPLESS_MAIN(TimeConversionTest);

#include "tst_timeconversiontest.moc"