diff options
author | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-02-06 09:50:44 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2018-02-13 14:52:01 +0000 |
commit | d08e0e861acadf3a354d3833dd5623ef71fa7a4b (patch) | |
tree | 0ba7f8ea33beff8a2492a2927630c5c349f889a5 /src/testlib/doc/snippets | |
parent | 357822818d97119a42f24e2285620187213ec2e1 (diff) |
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>
Diffstat (limited to 'src/testlib/doc/snippets')
-rw-r--r-- | src/testlib/doc/snippets/code/doc_src_qtestlib.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp index 0dc45bef76..de301b8df9 100644 --- a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp +++ b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp @@ -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] |