Reputation: 65
I want to add testfiles to a testsuite at runtime and my test files are not extending to Testcase as i am using junit 4.11.
Below is the code:
@RunWith(org.junit.runners.AllTests.class)
class MasterTester extends TestCase{
public static TestSuite suite1() {
TestSuite suite = new TestSuite();
for(Class<? extends TestCase> klass : gatherTestClasses()) {
suite.addTestSuite(klass);
}
return suite;
}
private static Class<?> gatherTestClasses()
{
return AbcIT.class;//getting a compile time error
}
}
I am getting a compile time error saying class of type cannot be added to class
Please suggest?
Upvotes: 0
Views: 2564
Reputation: 1567
Perhaps have a look at @Andrejs answer over here as he mentions dynamically adding JUnit 4 testcases to a testsuite:
@RunWith(AllTests.class)
public class SomeTests
{
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new JUnit4TestAdapter(Test1.class));
suite.addTest(new JUnit4TestAdapter(Test2.class));
return suite;
}
}
Upvotes: 1