5

Is it possible to get a TestRunner to run a Test Suite that's been created programmatically?

The Block4JunitTestRunner for example takes the Suite class as the constructor argument. However, I can't do this since the Suite isn't a concrete Suite. I dynamically add TestCases to a TestSuite and now I need a TestRunner to run it so im able to get Junit report the test failures/success/errors as normal. (

Thanks.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
Nick
  • 1,269
  • 5
  • 31
  • 45
  • could you please explain why do you need such a behavior? I mean when exactly test cases are added dynamically - during the runtime? are they generated by cglib or something, and if so what's the added value to see them in reports? i'm quite sure that what you're asking can be done only by extending the junit itself but I don't see why should it be done like this... Thanks – Mark Bramnik Feb 09 '13 at 04:59
  • @Ash, did you find out how do this? I am looking for this feature as well. I find that Junit3 can easily do this with Test and TestSuite classes, but not Junit4. – xkrz Feb 14 '14 at 20:12

1 Answers1

0

SuiteRunner

BlockJunit4ClassRunnerForInstance

Example Suite

This suite runner requires that you provide a static method returning a list of test instances e.g.

public static List<Object> testInstances(){
    ArrayList<Object> objects = new ArrayList<Object>();
    ..
    return objects;
}

The original behaviour of the block runner is to create a new instance per test method, so you might need to do more work in the setup to keep the tests independent.

roby
  • 3,103
  • 1
  • 16
  • 14
  • 1
    This doesn't really solve my problem. The TestCases are created problematically. I'd like to be able to pass a bunch of test case instances to a runner. – Nick Feb 08 '13 at 10:13