Module test with arguments


I wonder how to add arguments to test cases for different purposes. Not just data but other flags or arguments. After inspection of some ITK test files and the related CMakeLists.txt my guess is that i just need to add my arguments after the test function call as stated in the module creation guide does not help either:

Test commands should call the test driver executable, followed by options for the test, followed by the test function name, followed by arguments that are passed to the test. […]

My take:

itk_add_test(NAME itkMyModuleTest
  COMMAND MyModuleTestDriver itkMyModuleTest argument0 argument1

When I start the test driver and choose the test no arguments are provided to (this is an simplified example):

int itkMultiObjectRegistrationFrameworkTest(int argc, char* argv[])
    std::cout << argc << std::endl;
    std::cout << argv[0] << std::endl;
    std::cout << argv[1] << std::endl;
    return EXIT_SUCCESS;

and the test exits with an exception. If I run my test without the argument printing lines everything is fine. I can use my module as remote model in other application. Just the tests are not done because of this. :pensive:

What do I miss along the process of building the module? Can someone provide insight or help?


Hello @Gordian,

It is surprising that this is failing. I would expect it to work as long as the arguments you are passing are not “reserved” arguments used by the test driver. What the test driver does (see here) is:

  • parse the arguments of your command line
  • Remove the ones it understand as being his own arguments
  • Create a vector of the other arguments.

Then is runs your test using the arguments that it found belonging to your test. To debug your problem, I suggest to either add some debug statements inside here or inside here.

Hope this helps.



i figured out how to solve the initial question. It was a misunderstanding of the test/CMakeLists.txt. On this list the RUN_TEST project is created and all the arguments provided to a test are used in this test run. Since I wanted to test only particular classes and not all of them everytime I needed to select one of the tests in the debugging setting of the driver.

For all who encounter the same problem:
All arguments in the test/CMakeLists.txt are not used in the case the test driver is started from within the Visual Studio environment. Instead you need to provide the test name and the arguments you want to use as debugging arguments. This can be done with the “RightClick on test driver project”->Properties->Debugging->Debugging arguments:

YourTestName arg1 arg2 ...

If no arguments are provided the test driver offers a list of available test but you cannot use arguments. If your provide arguments without a test name as the first input the argument is handled as test name and the driver will not find a test. Then the process fails.

Thanks to @fbudin topoint out a place to start understanding the test procedure.

1 Like