Documentation/Nightly/Developers/Tutorials/CxxTests
From Slicer Wiki
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, us 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 include EXTRA_INCLUDE header file.
- In your testing code, if you expect errors or warnings: incclude 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):