Module test with arguments


(Gordian) #1


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?


(Francois Budin) #2

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.