diff options
author | Leena Miettinen <riitta-leena.miettinen@qt.io> | 2019-10-15 15:58:39 +0200 |
---|---|---|
committer | Leena Miettinen <riitta-leena.miettinen@qt.io> | 2019-10-30 14:50:57 +0200 |
commit | 949fc2860e6472e105faff5dea9780cc467c9950 (patch) | |
tree | cb7cb9b371cffb4a51b983917ae6f2bfbde12bc9 /src | |
parent | 58f56950848bae9c90da3873090c7698e0128b12 (diff) |
Doc: Add best-practices-info about initialization and clean-up
From https://wiki.qt.io/Writing_Unit_Tests
Change-Id: I20027066640ca797a2330f6daa81468f03921a69
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/doc/src/qttestlib-manual.qdoc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc index ee7767b5a5..a72ba1db91 100644 --- a/src/testlib/doc/src/qttestlib-manual.qdoc +++ b/src/testlib/doc/src/qttestlib-manual.qdoc @@ -102,6 +102,20 @@ \li \c{cleanup()} will be called after every test function. \endlist + Use \c initTestCase() for preparing the test. Every test should leave the + system in a usable state, so it can be run repeatedly. Cleanup operations + should be handled in \c cleanupTestCase(), so they get run even if the test + fails. + + Use \c init() for preparing a test function. Every test function should + leave the system in a usable state, so it can be run repeatedly. Cleanup + operations should be handled in \c cleanup(), so they get run even if the + test function fails and exits early. + + Alternatively, you can use RAII (resource acquisition is initialization), + with cleanup operations called in destructors, to ensure they happen when + the test function returns and the object moves out of scope. + If \c{initTestCase()} fails, no test function will be executed. If \c{init()} fails, the following test function will not be executed, the test will proceed to the next test function. |