Improve testlib example a bit

Assuming this is someone's first contact with testlib, we want to
mention QCOMPARE. Make the whole thing a bit more readable instead of
squeezing everything into single lines and add a bit more code.

Change-Id: I76908003427277670d1199774083a3ee01b8747c
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Nico Vertriest <nico.vertriest@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Frederik Gladhorn 2018-02-06 09:50:44 +01:00
parent 357822818d
commit d08e0e861a

View File

@ -48,19 +48,41 @@
**
****************************************************************************/
#include <QtTest>
//! [0]
class MyFirstTest: public QObject
{
Q_OBJECT
private:
bool myCondition()
{
return true;
}
private slots:
void initTestCase()
{ qDebug("called before everything else"); }
{
qDebug("Called before everything else.");
}
void myFirstTest()
{ QVERIFY(1 == 1); }
{
QVERIFY(true); // check that a condition is satisfied
QCOMPARE(1, 1); // compare two values
}
void mySecondTest()
{ QVERIFY(1 != 2); }
{
QVERIFY(myCondition());
QVERIFY(1 != 2);
}
void cleanupTestCase()
{ qDebug("called after myFirstTest and mySecondTest"); }
{
qDebug("Called after myFirstTest and mySecondTest.");
}
};
//! [0]