I am trying to bundle my tests in a TestSuite which will pick up files from a directory and run each one after loading spring context.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/META-INF/spring/context-test.xml"})
public class MyTestCase extends TestCase{
private String fileName;
public MyTestCase(String fileName){
this.fileName = fileName;
}
@Resource private Processor processor;
@Before
public void setup(){
...
}
@Test
public void test(){
Read file and run test..
...
}
}
If I do this, it doesn’t recognize spring annotations
public class MyTestSuite extends TestCase{
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(new MyTestCase("file1"));
suite.addTest(new MyTestCase("file2"));
return suite;
}
}
I looked it up and found: Spring 3+ How to create a TestSuite when JUnit is not recognizing it , which suggests that I should use JUnit4TestAdapter. Problem with JUnitTestAdapter is that it doesn’t allow me to pass in parameters and also would not take MyTestSuite.suite(). I can only do something like:
public class MyTestSuite{
public static Test suite(){
return new JUnit4TestAdapter(MyTestCase.class);
}
}
Your response is highly appreciated.
Thanks
I had to use deprecated AbstractSingleSpringContextTests to achieve this. AbstractSingleSpringContextTests is from the times when TestContext framework was not available.
Its not the best solution, but it works. Please post if you have a better idea.