ITK/Code Coverage Practices

From KitwarePublic
< ITK
Revision as of 20:42, 29 August 2011 by Andinet (talk | contribs)
Jump to navigationJump to search

Overview

  • The target code coverage is 95%
  • Historically we have only achieved 84%.
  • The practices described in this page should help us reach the target.

How to compute Code Coverage locally

Step 1

  • Use Linux or Mac

Step 2

  • Add the CMake flags:
      CMAKE_CXX_FLAGS:STRING=-g -O0  -fprofile-arcs -ftest-coverage
      CMAKE_C_FLAGS:STRING= -g -O0  -fprofile-arcs -ftest-coverage

Step 3

  • Configure to compile ITK for Debug
  • by setting the CMake variable
                    CMAKE_BUILD_TYPE  Debug

Step 4

  • From the binary directory type the "ctest" expression that select the tests that you want use to generate coverage (Ideally this should only need to be the unit tests of the class in question).
  • For example:
               ctest  -R   itkHDF5ImageIOTest   -V   -N
  • This will print to the console the command line instructions needed to run the tests (-V option), but without running the tests (-N option).

Step 5

  • From the binary directory type the path to this script in the ITK source tree and add the selection expression that you put in front of ctest.
  • For example:
       computeCodeCoverageLocallyForOneTest.sh ./Modules/IO/HDF5 -R  itkHDF5ImageIOTest
  • This will run the selected tests in ITK and generate code coverage for the entire toolkit, but only from the test that you have selected. The code coverage report will be generated in HTML and will be presented with Firefox.