Changeset 54af66bd in subsurface


Ignore:
Timestamp:
Apr 15, 2014, 11:03:38 AM (3 years ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
Mtest, android_test, dcDownload, forTomaz, foratdotde, gitMerge, gitdebug, gitpictures, ios, master, mergeKirigamiPort, pictimeshift, resolutionIndependence, spinner, testTomaz, testing, v4.2-branch, v4.4-branch, v4.5-branch
Children:
c6295b7
Parents:
2e80d79
git-author:
Miika Turkia <miika.turkia@…> (04/15/14 10:09:00)
git-committer:
Dirk Hohndel <dirk@…> (04/15/14 11:03:38)
Message:

Information on writing test cases

This information is mainly from Tomaz on IRC with references added to Qt
documentation on the subject.

Signed-off-by: Miika Turkia <miika.turkia@…>
Signed-off-by: Dirk Hohndel <dirk@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Readme.testing

    rbce0b43 r54af66bd  
    1515example in the tests folder and add the last three lines of the CMakeLists.txt file
    1616adapted to your test.
     17
     18
     19
     20To create a new test you can do one of the following (information
     21provided by Tomaz on IRC):
     22
     231) Create a new private slot on an already created test class
     242) Implement the test there, and compare the expected result with the
     25correct result with QCOMPARE:
     26
     27void testRedCeiling();
     28testRedCeiling()
     29{
     30        load_dive("../dive/testDive.xml");
     31        calculated_ceiling();
     32        QCOMPARE( dive->ceiling->color(), QColor("red"));
     33}
     34
     353) Run the test case and see result
     36
     37$ make test
     38
     39If the color is not QColor("red"), when you run the test you will get a
     40failure. Then you run a command to get a more verbose output and see in
     41which part the test fails.
     42
     43$ ctest -V
     44
     454) Fix the test case
     46
     475) Look at the existing test cases if you run into trouble or need more
     48ideas. E.g. running following command will show the first test cases
     49written for unit conversions:
     50
     51$ git show 019edd065fd1eefd5f705c42bce23255bb5e20ac
     52
     53Also the Qt documentation is good source for more information:
     54
     55http://qt-project.org/doc/qt-4.8/qtest.html
     56http://qt-project.org/doc/qt-5/qtest.html
     57
     586) To create a new test class, copy the last three lines of the CMake,
     59and duplicate it with the new class / file.
     60
     61Each "test" can have N test cases on it (each private slot counts as one
     62test) and is executable. When one runs make, these test cases are
     63compiled and when running "make test" they will be executed. Of course,
     64the test cases can be run manually as well.
     65
     66There are three main test macros that we use, but of course many more
     67are available (check the Qt documentation):
     68
     69QCOMPARE(value, expected)
     70QVERIFY(boolean)
     71QVERIFY2(boolean, "error message on fail")
     72
     73If expecting a test case to fail, use
     74
     75QEXPECT_FAIL("", "This test case fails, as it is not yet fully implemented", Continue);
     76
     77To link libraries, use the following macro:
     78
     79TARGET_LINK_LIBRARIES(TestCaseName ${QT_LIBRARIES} subsurface_corelib)
Note: See TracChangeset for help on using the changeset viewer.