My organization is using CppUnit and I am trying to run the same test using different parameters. Running a loop inside the test is not a good option as any failure will abort the test. I have looked at TestDecorator
and TestCaller
but neither seems to really fit. Code samples would be helpful.
It does not appear possible in CppUnit to parameterize a test case directly (see here and here). However, you do have a few options:
RepeatedTest
You may be able to make some clever use of the built-in RepeatedTest
decorator. This allows a test case to be run multiple times (though without parameterization).
I'll admit to never having used this myself, but perhaps you could have the RepeatedTest
drive some gatekeeper function, which would (using a class static variable, perhaps?) pick a different input with every run. It would in turn call the true function you'd like to test with that value as input.
TestCase
subclassOne person on CppUnit's SourceForge page claims to have written a subclass of TestCase
that will run a particular test an arbitrary number of times, although in a slightly different manner than the RepeatedTest
class offers. Sadly, the poster simply described the motivation for creating the class, but did not provide the source code. There was, however, an offer to contact the individual for more details.
The most straight-forward (but least automated) way to do this is to create a helper function that takes the parameter you'd like to pass on to your "real" function, and then have lots of individual test cases. Each test case would call your helper function with a different value.
If you choose either of the first two options listed above, I'd be interested in hearing about your experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With