Difference between revisions of "Documentation/Nightly/Developers/Tutorials/CxxTests"
From Slicer Wiki
(Created page with '<noinclude>{{documentation/versioncheck}}</noinclude> == Goal == Goal of Cxx tests is to test C++ classes as comprehensively as possible in the simplest possible environment (wi…') |
|||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
* To reduce the number of individual executable files, typically many test cases are packaged into a single executable using and CTK's [http://www.commontk.org/docs/html/group__CMakeUtilities.html SIMPLE_TEST utilities] | * To reduce the number of individual executable files, typically many test cases are packaged into a single executable using and CTK's [http://www.commontk.org/docs/html/group__CMakeUtilities.html SIMPLE_TEST utilities] | ||
* The test process must exit with zero (EXIT_SUCCESS) error code in case of success and non-zero (EXIT_FAILURE) in case of failure | * The test process must exit with zero (EXIT_SUCCESS) error code in case of success and non-zero (EXIT_FAILURE) in case of failure | ||
− | * It is strongly recommended to exit with failure if any unexpected VTK error or warning messages are logged. To achieve this, | + | * It is strongly recommended to exit with failure if any unexpected VTK error or warning messages are logged. To achieve this, use the [https://github.com/Slicer/Slicer/blob/master/Libs/vtkAddon/vtkTestingOutputWindow.h vtkTestingOutputWindow] class (and its convenience macros) defined in the vtkAddon library |
− | ** In the CMakeLists.txt of your Cxx tests ( | + | ** In the CMakeLists.txt of your Cxx tests (see [https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Widgets/Testing/CMakeLists.txt Libs\MRML\Widgets\Testing\CMakeLists.txt] as an example): |
− | *** Add TESTING_OUTPUT_INIT() | + | *** Add ''TESTING_OUTPUT_INIT()'' to ''CMAKE_TESTDRIVER_BEFORE_TESTMAIN'' |
− | *** Add TESTING_OUTPUT_ASSERT_WARNINGS_ERRORS(0) | + | *** Add ''TESTING_OUTPUT_ASSERT_WARNINGS_ERRORS(0)'' to ''CMAKE_TESTDRIVER_AFTER_TESTMAIN'' |
− | *** Add #include <vtkTestingOutputWindow.h> to the | + | *** Add ''#include <vtkTestingOutputWindow.h>'' to the included ''EXTRA_INCLUDE'' header file. |
− | ** In your testing code, if you expect errors or warnings: | + | ** In your testing code, if you expect errors or warnings: include ''vtkTestingOutputWindow.h'' and put code that logs errors or warnings between these macros (see examples in [https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Widgets/Testing/ Libs\MRML\Widgets\Testing]): |
− | *** TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_BEGIN() / TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_END() – if errors or warnings may be logged | + | *** ''TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_BEGIN()'' / ''TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_END()'' – if errors or warnings may be logged |
− | *** TESTING_OUTPUT_ASSERT_WARNINGS_BEGIN() / TESTING_OUTPUT_ASSERT_WARNINGS_END() – if errors or warnings must be logged | + | *** ''TESTING_OUTPUT_ASSERT_WARNINGS_BEGIN()'' / ''TESTING_OUTPUT_ASSERT_WARNINGS_END()'' – if errors or warnings must be logged |
Latest revision as of 20:57, 26 October 2015
Home < Documentation < Nightly < Developers < Tutorials < CxxTests
For the latest Slicer documentation, visit the read-the-docs. |
Goal
Goal of Cxx tests is to test C++ classes as comprehensively as possible in the simplest possible environment (with minimum usage of other classes).
The tests are run as part of the nightly test process and submitted to the slicer dashboard.
Implementation
- Test execution is managed by CMake/CTest
- To reduce the number of individual executable files, typically many test cases are packaged into a single executable using and CTK's SIMPLE_TEST utilities
- The test process must exit with zero (EXIT_SUCCESS) error code in case of success and non-zero (EXIT_FAILURE) in case of failure
- It is strongly recommended to exit with failure if any unexpected VTK error or warning messages are logged. To achieve this, use the vtkTestingOutputWindow class (and its convenience macros) defined in the vtkAddon library
- In the CMakeLists.txt of your Cxx tests (see Libs\MRML\Widgets\Testing\CMakeLists.txt as an example):
- Add TESTING_OUTPUT_INIT() to CMAKE_TESTDRIVER_BEFORE_TESTMAIN
- Add TESTING_OUTPUT_ASSERT_WARNINGS_ERRORS(0) to CMAKE_TESTDRIVER_AFTER_TESTMAIN
- Add #include <vtkTestingOutputWindow.h> to the included EXTRA_INCLUDE header file.
- In your testing code, if you expect errors or warnings: include vtkTestingOutputWindow.h and put code that logs errors or warnings between these macros (see examples in Libs\MRML\Widgets\Testing):
- TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_BEGIN() / TESTING_OUTPUT_IGNORE_WARNINGS_ERRORS_END() – if errors or warnings may be logged
- TESTING_OUTPUT_ASSERT_WARNINGS_BEGIN() / TESTING_OUTPUT_ASSERT_WARNINGS_END() – if errors or warnings must be logged
- In the CMakeLists.txt of your Cxx tests (see Libs\MRML\Widgets\Testing\CMakeLists.txt as an example):