Luke St.Clair wrote:
I need to run the same unit test case more than 10 times (around 150
tests in the test case), with 2-3 parameters changed each time.For instance, if I had unit tests to examine a "Person", with a
required parameter "name" - let's say I want to run the same
Test::Unit::TestCase on 10 different people, with different names but
everything else the same. All test cases run the same code, just with
the one (or two) parameters tweaked.Let's say I have 150 tests for a Person - I'd rather not end up with
1500 tests, each of the 150 tests exactly duplicated for a different
"name".I'll have a hierarchy of tests cases, in suites, which may help
Is there some way to:
1) set a global variable in the "parent" test suite that the children
see? Seems like the answer to this is no
2) Pass an arg to the test case as a whole? Don't see anyway to do
this in the docs
3) Do something else that will keep this test code compliant with DRY?What's the right approach here?
my first thought is to have your test_something methods call protected methods of the class (that you create). Just because it's a unit test doesn't mean it's not also a perfectly normal object - I often forget that one. Using this in conjunction with a setup method and you should be able to get things going as you want. IMHO hardwiring test data into your test classes isn't a Bad Thing. It helps you keep your data/data structures smart and your code dumb, so you can simply have an array or something similar of the parameters you want, and then cycle through those.
HTH,
Michael