[Insight-users] Unit Testing

Luis Ibanez luis.ibanez at kitware.com
Sat May 19 17:58:38 EDT 2007


Hi Matt,

Yes, your observation is correct.

 From the cmake help command line:


 > cmake --help-command ADD_TEST


ADD_TEST
Add a test to the project with the specified arguments.

ADD_TEST(testname Exename arg1 arg2 ...)

If the ENABLE_TESTING command has been run, this command adds a test
target to the current directory. If ENABLE_TESTING has not been run,
this command does nothing. The tests are run by the testing subsystem
by executing Exename with the specified arguments. Exename can be
either an executable built by built by this project or an arbitrary
executable on the system (like tclsh).


The "Exename" must be the target of a previous ADD_EXECUTABLE()
command.


Note that in ITK itself, this is done in a more complex way,
because we group tens of tests in a single executable, and
then we call each one of them by passing a name as the argument
to that "test driver" executable. In this context, the .cxx
of each test, only contains a function with the name of the
test. The functions are called from the test driver (for
example itkCommonTest.cxx is one of the test driver in
Testing/Code/Common).



If you are dealing with a few list of tests (< 50), it is not
worth to use test drivers. You probably want to stick to the
simple rule of   "1 test = 1 executable". In which case, each
one of your .cxx unit tests will have a main() function and
will generate an independent executable.




     Regards,



        Luis



---------------------
Matt Kelsey wrote:
> Hello again,
> I have a couple of additional questions about unit testing in ITK if
> you have  a moment.
> 
> I see from the example that:
> ADD_TEST(SimpleTest ${EXECUTABLE_OUTPUT_PATH}/SimpleTest Hello)
> SimpleTest is the test name,
> ${EXECUTABLE_OUTPUT_PATH}/SimpleTest is the test executable,
> and Hello is a command line parameter.
> 
> I take it from this that the "SimpleTest" executable has to be
> generated from some other command within the CMakeLists file.  Is the
> way to do this simply to add another "ADD_EXECUTABLE" with all of the
> necessary files for each test?  In this scenario, it seems that each
> SimpleTestN.cpp would contain a main() and be used to create a
> separate executable.
> Am I off base here or is that pretty much how it goes?
> 
> Thanks for your insight,
> Matt
> 
> On 5/16/07, Matt Kelsey <mkelsey at gmail.com> wrote:
> 
>> Thanks Luis, I think that will be very helpful.
>>
>> Matt
>>
>> On 5/16/07, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>> >
>> > Hi Matt,
>> >
>> > You may want to look also at:
>> >
>> >    http://www.cmake.org/Wiki/CMake_Testing_With_CTest
>> >
>> >
>> > Please let us know if you have further questions,
>> >
>> >
>> >     Thanks
>> >
>> >
>> >
>> > -----------------------
>> > Dan Mueller wrote:
>> > > Hi Matt,
>> > >
>> > > I'm not an expert regarding the testing system used by ITK, but
>> > > hopefully I can at least help point you in the right direction.
>> > >
>> > > ITK uses CMake to generate tests covering different aspects of the 
>> code,
>> > > including: unit tests, blackbox tests, and regression tests. Have a
>> > > browse of Testing/Code/BasicFilters/CMakeLists.txt to see examples of
>> > > how to use CMake to add unit and regression tests. The CMake
>> > > documentation may also be useful:
>> > > http://www.cmake.org/HTML/Documentation.html (particularly the 
>> ADD_TEST
>> > > command). Obviously you can use the CMake ADD_TEST command in your 
>> own
>> > > projects as well.
>> > >
>> > > Maybe check out the following pages:
>> > >     http://www.itk.org/Wiki/Itk_FAQ#Testing
>> > >     http://www.itk.org/HTML/Testing.htm
>> > >
>> > > HTH
>> > >
>> > > Cheers, Dan
>> > >
>> > > Matt Kelsey wrote:
>> > >
>> > >> Does anyone know of a document or tutorial that details the ITK
>> > >> testing structure.  Does it support something in the way of Unit
>> > >> Tests?  I'd like to have a structured way of testing all of my 
>> modules
>> > >> and would be happy to use a built in feature if it's there.
>> > >>
>> > >> Thanks for any thoughts.
>> > >>
>> > >> Matt
>> > >> _______________________________________________
>> > >> Insight-users mailing list
>> > >> Insight-users at itk.org
>> > >> http://www.itk.org/mailman/listinfo/insight-users
>> > >
>> > >
>> > > 
>> ------------------------------------------------------------------------
>> > >
>> > > _______________________________________________
>> > > Insight-users mailing list
>> > > Insight-users at itk.org
>> > > http://www.itk.org/mailman/listinfo/insight-users
>> >
>>
> 


More information about the Insight-users mailing list