ITK/Release 4/Modularization/ Add tests

From KitwarePublic
< ITK‎ | Release 4‎ | Modularization
Revision as of 20:20, 3 September 2013 by Xiaoxiao (talk | contribs)
Jump to navigationJump to search

Non-regression tests

The same way it used to be, except the newer syntax in "add_test" command:

 add_executable(itkBinaryThresholdFilterTest itkBinaryThresholdFilterTest.cxx)

 target_link_libraries(itkBinaryThresholdFilterTest ${ITK-BinaryThreshold_LIBRARIES})
      
 # adopt the modern CMake syntax :[NAME, COMMAND]

 itk_add_test(NAME itkBinaryThresholdFilterTest  
         COMMAND itkBinaryThresholdFilterTest input.png output.png)


Regression tests

Approach A

Using the test driver macro The CMake macro "CreateTestDriver" defined in

 Module/Core/TestKernal/CreateTestDriver.cmake

is designed for grouped regression tests in ITK.

All the tests in one module share one test driver.

  set(ITKFooFilterTests
     itkFooFilterTest1.cxx
     itkFooFilterTest2.cxx)

  CreateTestDriver(ITKFooFilter  "${ITK_FooFilter-Test_LIBRARIES}"  "${ITK-FooFilterTest}")

  itk_add_test(NAME  itkFooFilterTest1
           COMMAND  ITKFooFilterTestDriver  itkFooFilterTest1)
 
  itk_add_test(NAME  itkFooFilterTest2
           COMMAND  ITKFooFilterTestDriver  itkFooFilterTest2)


You can find Approach A used in most of the ITK modules. for example in

   ITK/Modules/IO/BMP/test/CMakeLists.txt

Approach B

Stand-alone regression tests

There is also a test driver executable("itkTestdriver") designed for stand-alone regression tests. For instance, all the tests in Examples are stand-alone programs each has its own main function call, in which case, the approach A is not appropriate.


   add_exectuable(itkFooTest itkFooTest.cxx)

   target_line_libraries( itkFooTest ${ITK_LIBRARIES})

   itk_add_test(NAME  itkFooTest
            COMMAND  itkTestDriver
            --compare  outputBaseline.png output.png
                       '''$<TARGET_FILE:'''itkFooFilterTest'''>''' input.png output.png)


The new syntax

    $<TARGET_FILE: xxx> 

in the add_test command triggers CMake to locate the executable automatically. No need to specify the path for the executable here.

You can find Approach B used in Examples.

For example in

 ITK/Examples/Filtering/test/CMakeLists.txt


Add testing data to ITK

  Please refer to: | Add Data