ITK/Release 4/Modularization/ Add tests: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
== Non-regression tests ==
== Non-regression tests ==
The same way it used to be, except the newer syntax in "add_test" command:
The same way it used to be, except the newer syntax in "add_test" command:
  e.g. add_executable(itkBinaryThresholdFilterTest itkBinaryThresholdFilterTest.cxx)
 
      target_link_libraries(itkBindaryThresholdFilterTest ${ITK-BinaryThreshold_LIBRARIES})
{{#tag:syntaxhighlight
|
 
add_executable(itkBinaryThresholdFilterTest itkBinaryThresholdFilterTest.cxx)
 
target_link_libraries(itkBindaryThresholdFilterTest ${ITK-BinaryThreshold_LIBRARIES})
        
        
      #adopt the modern CMake syntax :[NAME, COMMAND]
# adopt the modern CMake syntax :[NAME, COMMAND]
      add_test(NAME itkBinaryThresholdFilterTest   
 
            COMMAND itkBinaryThresholdFilterTest input.png output.png)
add_test(NAME itkBinaryThresholdFilterTest   
        COMMAND itkBinaryThresholdFilterTest input.png output.png)
|lang=cmake}}




Line 21: Line 29:


   CreateTestDriver(ITK-FooFilter  "${ITK_FooFilter-Test_LIBRARIES}"  "${ITK-FooFilterTest}")
   CreateTestDriver(ITK-FooFilter  "${ITK_FooFilter-Test_LIBRARIES}"  "${ITK-FooFilterTest}")
      add_test(NAME  itkFooFilterTest1
 
            COMMAND  itk-FooFilterTestDriver  itkFooFilterTest1)
  add_test(NAME  itkFooFilterTest1
      add_test(NAME  itkFooFilterTest2
          COMMAND  itk-FooFilterTestDriver  itkFooFilterTest1)
            COMMAND  itk-FooFilterTestDriver  itkFooFilterTest2)
  add_test(NAME  itkFooFilterTest2
          COMMAND  itk-FooFilterTestDriver  itkFooFilterTest2)




Line 39: Line 49:
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 suitable.
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 suitable.


e.g.   add_exectuable(itkFooTest itkFooTest.cxx)
 
        target_line_libraries( itkFooTest ${ITK_LIBRARIES})
{{#tag:syntaxhighlight
        add_test(NAME  itkFooTest
|
              COMMAND  itkTestDriver
   add_exectuable(itkFooTest itkFooTest.cxx)
 
  target_line_libraries( itkFooTest ${ITK_LIBRARIES})
 
  add_test(NAME  itkFooTest
            COMMAND  itkTestDriver
             --compare  outputBaseline.png output.png
             --compare  outputBaseline.png output.png
                       '''$<TARGET_FILE:'''itkFooFilterTest'''>''' input.png output.png)
                       '''$<TARGET_FILE:'''itkFooFilterTest'''>''' input.png output.png)
|lang=cmake}}
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.


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


You can find Approach b) used in Examples (e.g. "ITK/Examples/Filtering/test/CMakeLists.txt").
  ITK/Examples/Filtering/test/CMakeLists.txt

Revision as of 22:55, 4 April 2011

Non-regression tests

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

<syntaxhighlight lang="cmake">

add_executable(itkBinaryThresholdFilterTest itkBinaryThresholdFilterTest.cxx)
target_link_libraries(itkBindaryThresholdFilterTest ${ITK-BinaryThreshold_LIBRARIES})
     
# adopt the modern CMake syntax :[NAME, COMMAND]
add_test(NAME itkBinaryThresholdFilterTest  
        COMMAND itkBinaryThresholdFilterTest input.png output.png)

</syntaxhighlight>


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.

<syntaxhighlight lang="cmake">

 set(ITK-FooFilterTests
    itkFooFilterTest1.cxx
    itkFooFilterTest2.cxx)
 CreateTestDriver(ITK-FooFilter  "${ITK_FooFilter-Test_LIBRARIES}"  "${ITK-FooFilterTest}")
 add_test(NAME  itkFooFilterTest1
          COMMAND  itk-FooFilterTestDriver  itkFooFilterTest1)

 add_test(NAME  itkFooFilterTest2
          COMMAND  itk-FooFilterTestDriver  itkFooFilterTest2)


</syntaxhighlight>


You can find Approach (b) 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 suitable.


<syntaxhighlight lang="cmake">

  add_exectuable(itkFooTest itkFooTest.cxx)
  target_line_libraries( itkFooTest ${ITK_LIBRARIES})
  add_test(NAME  itkFooTest
           COMMAND  itkTestDriver
           --compare  outputBaseline.png output.png
                      $<TARGET_FILE:itkFooFilterTest> input.png output.png)

</syntaxhighlight>


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