From d08e0e861acadf3a354d3833dd5623ef71fa7a4b Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 6 Feb 2018 09:50:44 +0100 Subject: [PATCH] Improve testlib example a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Nico Vertriest Reviewed-by: Tor Arne Vestbø --- .../doc/snippets/code/doc_src_qtestlib.cpp | 30 ++++++++++++++++--- 1 file 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 0dc45bef768..de301b8df98 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 + //! [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]