tags:

views:

268

answers:

1

I'm trying to migrate to JUnit 4 and I'm not clear about the correct way to set up test suites.

I know how to set up a test suite with fixed tests using the @SuitesClasses annotation.

However, I want to have a top-level suite class, where I can programatically decide which test classes or suites I want to load. I know that there are addTest and addTestSuite operations in the TestSuite class.

However, if I define a TestSuite subclass with a constructor that attempts to add these tests and try to run it, I get an error "Must have SuiteClasses annotation".

Any idea how to do this?

+1  A: 

I would recommend creating a subclass of the BlockJUnit4ClassRunner and pull in the classes you want to test manually. The protected methods of the class do all the hard work for you, although you might want to tweak the Descriptions a bit to make sure the results are all unique in the output files.

Andrew Cowan