Skip to content

Commit 4ea7e2a

Browse files
thewtexCode Review
authored andcommitted
Merge "DOC: Add testing section to SW guide."
2 parents 2fc0987 + 8bdf061 commit 4ea7e2a

4 files changed

Lines changed: 125 additions & 15 deletions

File tree

SoftwareGuide/Art/Dashboard.jpg

-119 KB
Loading

SoftwareGuide/Latex/00-Preamble-Common.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
\usepackage[toc,page]{appendix}
99
\usepackage{verbatim}
1010
\usepackage{imakeidx}
11+
%\usepackage{siunitx}
1112
\usepackage[papersize={7.5in,9.25in},margin=1in]{geometry}
1213

1314
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SoftwareGuide/Latex/DG04-CreateAModule.tex

Lines changed: 95 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,12 @@ \section{Tests}
262262
Regression tests for a module are placed in the \code{test} directory. This
263263
directory will contain a \texttt{CMakeLists.txt} with the CMake configuration,
264264
test sources, and optional \texttt{Input} and \texttt{Baseline} directories,
265-
which contain test input and baseline image datasets, respectively.
265+
which contain test input and baseline image datasets, respectively. Placement
266+
of the input and baseline image datasets within a given module directory is
267+
preferred over placement in the general \texttt{Testing/Data} directory; this
268+
ensures that a module's data is only downloaded when the module is enabled. An
269+
exception to this rule may be widely used input datasets, such as the
270+
\texttt{cthead1.png} image.
266271
267272
An example CMake configuration for a test directory is shown below.
268273
@@ -304,22 +309,100 @@ \section{Tests}
304309
around the CMake \code{add\_test} command that will resolve content links in
305310
the \code{DATA} macro. Testing data paths are given inside the \code{DATA}
306311
macro. Content link files, stored in the source code directory, are replaced
307-
by actual content files in the build directory when CMake downloads the target
308-
at build time. A content link file has the same name as its target, but a
309-
\texttt{.md5} extension is added, and the \texttt{.md5} file's contents are
310-
only the MD5SUM hash of its target. Content links for data files in a Git
311-
distributed version control repository prevent repository bloat. To obtain
312-
content links, register an account with the \texttt{ITK} community at
313-
\url{https://midas3.kitware.com} and request upload permissions on the ITK
314-
mailing list.
312+
by actual content files in the build directory when CMake downloads the
313+
\code{ITKData} target at build time. A content link file has the same name as
314+
its target, but a \texttt{.md5} extension is added, and the \texttt{.md5}
315+
file's contents are only the MD5SUM hash of its target. Content links for data
316+
files in a Git distributed version control repository prevent repository
317+
bloat. To obtain content links, register an account with the \texttt{ITK}
318+
community at \url{https://midas3.kitware.com} and request upload permissions
319+
on the ITK mailing list. The content links may also be created locally: once
320+
the actual file at issue has been placed in the corresponding directory, run
321+
CMake configuration, and CMake provides the desired \texttt{.md5} extension
322+
content link file.
323+
324+
When a test requires a new (or modified) input or baseline image dataset,
325+
the corresponding content link files have to be provided as well. Image
326+
datasets provided should be kept as small as possible. As a rule of thumb,
327+
their size should be under 50~\textit{kB}.
315328
316329
Test commands should call the test driver executable, followed by options for
317330
the test, followed by the test function name, followed by arguments that are
318-
passed to the test. The test driver accepts options like \texttt{--compare} to
319-
compare output images to baselines or options that modify tolerances on
320-
comparisons.
331+
passed to the test. The test driver accepts options like \texttt{--compare}
332+
(or \texttt{--compare-MD5} when using the MD5SUM hash) to compare output images
333+
to baselines or options that modify tolerances on comparisons. An exhaustive
334+
list of options is displayed in \texttt{itkTestDriverInclude.h}.
321335
336+
A few rules must be acknowledged to actually write a units test file
337+
\texttt{itk<ClassName>Test.cxx} for a given ITK class:
338+
\begin{enumerate}
339+
\item All class methods must be exercised.
340+
\item Test cases with values for member variables different from the default
341+
ones should be provided. The usefulness of this rule is especially manifest
342+
for boolean members, whose value usually determines whether a large portion
343+
of code is exercised or not.
344+
\item Test cases to reach the exception cases within the class should be
345+
provided.
346+
\item Regression tests must be included for methods returning a value.
347+
\item When a test detects a failure condition it must return the
348+
\code{EXIT\_FAILURE} value; if a test exits normally, it must return
349+
the \code{EXIT\_SUCCESS} value.
350+
\end{enumerate}
351+
352+
In any case, ITK provides with a number of classes and macros that ease the
353+
process of writing tests and checking the expected results. The following is an
354+
exhaustive list of such tools:
355+
\begin{itemize}
356+
\item \texttt{itkTestingMacros.h}: it contains a number of macros that allow
357+
testing of basic object properties:
358+
\begin{itemize}
359+
\item \code{EXERCISE\_BASIC\_OBJECT\_METHODS()}: verifies whether the class and
360+
superclass names provided match the RTTI, and exercises the \code{PrintSelf()}
361+
method. Since the \code{PrintSelf()} method prints all class member variables,
362+
this macro, when exercised, can identify uninitialized member variables.
363+
\item \code{TEST\_SET\_GET\_VALUE()}: once a member variable value has been set
364+
using the corresponding Set macro, this macro verifies that the value provided
365+
to the \code{Set()} method was effectively assigned to the member variable
366+
by comparing it to the value returned by the \code{Get()} value.
367+
\item \code{TEST\_SET\_GET\_BOOLEAN()}: exercises the \code{Set()/Get()},
368+
and \code{On()/Off()} methods of class applied to a boolean member variable.
369+
\end{itemize}
370+
\item \code{TRY\_EXPECT\_NO\_EXCEPTION()}: exercises a method which is expected to
371+
return with no errors. It is only required for methods that are known to throw
372+
exceptions, such as I/O operations, filter updates, etc.
373+
\item \code{TRY\_EXPECT\_EXCEPTION()}: exercises a method in the hope of detecting
374+
an exception. This macro allows a test to continue its execution when setting
375+
test cases bound to hit a class' exception cases. It is only required for
376+
methods that are known to throw exceptions, such as I/O operations, filter
377+
updates, etc.
378+
\item \code{itkMath.h}: contains a series of static methods used for basic
379+
type comparison. Methods are available to perform fuzzy floating point equality
380+
comparison, e.g. \code{itk::Math::FloatAlmostEquals()}, to handle expected
381+
cross-platform differences.
382+
\end{itemize}
322383
384+
A test may have some input arguments. When a test does not need any input
385+
argument (e.g., it generates a synthetic input image), the \code{main}
386+
argument names may either be omitted (\code{int itk<ClassName>Test( int,
387+
char* [] )}), or the \code{itkNotUsed }macro can be used (\code{int
388+
itk<ClassName>Test( int itkNotUsed( argc ), char *itkNotUsed( argv ) [] )}),
389+
to avoid compiler warnings about unused variables.
390+
391+
The number of input arguments provided must be checked at the beginning of the
392+
test. If a test requires a fixed number of input arguments, then the argument
393+
number check should verify the exact number of arguments.
394+
395+
It is essential that a test is made quantitative, i.e., the methods' returned
396+
values and the test's output must be compared to a known ground-truth. As
397+
mentioned, ITK contains a series of methods to compare basic types. ITK also
398+
provide a powerful regression tool for a test that checks the validity of a
399+
process over an image, which is the most common case in ITK. To this end, the
400+
test is expected to write its output to a file. The first time the test is run,
401+
the output is expected to be manually placed within the test module's
402+
\texttt{Baseline} folder. Hence, when CTest is executed, the distance between
403+
the test's output and the expected output (i.e., the baseline) is computed. If
404+
the distance is below a configurable tolerance, the regression test is marked as
405+
a success.
323406
324407
\section{Wrapping}
325408
\label{sec:ModuleWrapping}

SoftwareGuide/Latex/DG05-SoftwareProcess.tex

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ \section{CDash Regression Testing System}
111111
Rational. (Other memory checking programs will be added in the future.)
112112

113113
\item[PrintSelf.] All classes in ITK are expected to print out all
114-
their instance variables (i.e., those with associated Set and Get
115-
methods) correctly. This test checks to make sure
116-
that this is the case.
114+
their instance (i.e., those with associated Set and Get
115+
methods) and their internal variables correctly. This test checks to
116+
make sure that this is the case.
117117

118118
\item[Unit.] Each class in ITK should have a corresponding unit test
119119
where the class functionalities are exercised and quantitatively
@@ -153,6 +153,32 @@ \section{CDash Regression Testing System}
153153
the dashboard. This is useful for tracking problems and keeping up to date
154154
with new additions to ITK.
155155

156+
\subsection{Developing tests}
157+
\label{subsec:developingTests}
158+
159+
As highlighted, testing is an essential part of ITK. Regression testing on a
160+
regular basis allows ITK to meet high code quality standards, and to enable
161+
reproducible research. Code coverage reported daily in CDash allows us to
162+
systematically measure the degree to which the ITK source code is reliable.
163+
Therefore, writing tests, and improving current tests and the testing
164+
infrastructure is crucial to ITK.
165+
166+
There are a number of scenarios when writing tests:
167+
\begin{itemize}
168+
\item \textbf{Modifying existing classes}. When modifying an existing class
169+
(either due to a bug or a performance improvement), it must be checked that
170+
existing tests exercise the new code. Otherwise, either the existing tests
171+
should be modified to include the appropriate cases for the new code to be
172+
exercised (without harm to existing cases), or a new test file may be required.
173+
\item \textbf{Contributing new classes}. When contributing a new class, a unit
174+
test or a few unit tests should be provided to check that the class is working
175+
as expected. The unit tests are expected to exercise all of the members of the
176+
new class.
177+
\end{itemize}
178+
179+
In either case, the tips and tools described in Section~\ref{sec:Tests} were
180+
developed to improve and facilitate the process.
181+
156182
\section{Working The Process}
157183
\label{sec:WorkingTheProcess}
158184

0 commit comments

Comments
 (0)