Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Single test, multiple data. How?

Tim Kosse
2006-08-24
2013-04-22
  • Tim Kosse
    Tim Kosse
    2006-08-24

    I basically want to test a particular method multiple times with different data (>50 different datasets).

    Is there any way to easily execute a test and pass it some custom data? The pseudocode below should demonstrate what I mean:

    // Pseudocode
    t_data somedata[50];
    ...
    for (int i = 0; i < 50; i++)
      sometest.run(somedata[i]);

     
    • john_1726
      john_1726
      2006-11-21

      You can't pass data directly to unit tests, but you could have multiple unit tests call a  function that takes as a parameter this test data.

       
    • otmane
      otmane
      2007-07-31

      u can do this with a CppUnit::TestCase.
      -u can create for example a costum Class , MyClass: public TestCase
      -pass the data in the class constructor
      -implement the virtual void runTest() function of TestCase Class

      After that u create a CppUnit::TestSuite that contain all your Tests with the right parameters.
      -u add the suite to your TestRunner
      -and run them

      Sorry for my bad english ;)
      Good luck