source: subsurface/Readme.testing

Mtestandroid_testdcDownloadforTomazforatdotdegitMergegitdebuggitpicturesiosmergeKirigamiPortpictimeshiftresolutionIndependencespinnertestTomaztestingv4.2-branchv4.4-branchv4.5-branch
Last change on this file was 54af66bd, checked in by Dirk Hohndel <dirk@…>, 3 years ago

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

  • Property mode set to 100644
File size: 2.5 KB
Line 
1Testing subsurface:
2
3Right now to test subsurface you need to have the 'cmake' executable
4to compile the source code of the tests and run them.
5
61 - create a folder 'build-tests' on the project root directory
72 - run cmake ( cmake .. )
83 - compile the software by invocking make
94 - run the tests by invocking make test
10(optional 5) if the tests are failing, a better way to see what's
11happening is to run ctest -V , this way the tests will still fail,
12but more verbosically - easyer to track them down.
13
14to create a new test, just implement copy the one provided by
15example in the tests folder and add the last three lines of the CMakeLists.txt file
16adapted 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 TracBrowser for help on using the repository browser.