Documentation/4.6/Developers/Tutorials/CxxTests

From Slicer Wiki
Revision as of 07:19, 7 November 2016 by UpdateBot (talk | contribs) (Nightly -> 4.6)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Home < Documentation < 4.6 < 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