Changeset 54af66bd in subsurface

Apr 15, 2014, 11:03:38 AM (4 years ago)
Dirk Hohndel <dirk@…>
Mtest, android_test, dcDownload, foratdotde, gitMerge, gitdebug, gitpictures, ios, master, mergeKirigamiPort, pictimeshift, resolutionIndependence, spinner, testTomaz, testing, v4.2-branch, v4.4-branch, v4.5-branch
Miika Turkia <miika.turkia@…> (04/15/14 10:09:00)
Dirk Hohndel <dirk@…> (04/15/14 11:03:38)

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@…>

1 edited


  • Readme.testing

    rbce0b43 r54af66bd  
    1515example in the tests folder and add the last three lines of the CMakeLists.txt file
    1616adapted to your test.
     20To create a new test you can do one of the following (information
     21provided by Tomaz on IRC):
     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:
     27void testRedCeiling();
     30        load_dive("../dive/testDive.xml");
     31        calculated_ceiling();
     32        QCOMPARE( dive->ceiling->color(), QColor("red"));
     353) Run the test case and see result
     37$ make test
     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.
     43$ ctest -V
     454) Fix the test case
     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:
     51$ git show 019edd065fd1eefd5f705c42bce23255bb5e20ac
     53Also the Qt documentation is good source for more information:
     586) To create a new test class, copy the last three lines of the CMake,
     59and duplicate it with the new class / file.
     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.
     66There are three main test macros that we use, but of course many more
     67are available (check the Qt documentation):
     69QCOMPARE(value, expected)
     71QVERIFY2(boolean, "error message on fail")
     73If expecting a test case to fail, use
     75QEXPECT_FAIL("", "This test case fails, as it is not yet fully implemented", Continue);
     77To link libraries, use the following macro:
     79TARGET_LINK_LIBRARIES(TestCaseName ${QT_LIBRARIES} subsurface_corelib)
Note: See TracChangeset for help on using the changeset viewer.