【发布时间】:2011-09-08 22:29:10
【问题描述】:
我正在尝试将我的测试捆绑在一个 TestSuite 中,它将从一个目录中提取文件并在加载 spring 上下文后运行每个文件。
@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..
...
}
}
如果我这样做,它不会识别弹簧注释
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;
}
}
我查了一下,发现:Spring 3+ How to create a TestSuite when JUnit is not recognizing it,这表明我应该使用 JUnit4TestAdapter。 JUnitTestAdapter 的问题是它不允许我传递参数,也不会采用 MyTestSuite.suite()。我只能这样做:
public class MyTestSuite{
public static Test suite(){
return new JUnit4TestAdapter(MyTestCase.class);
}
}
非常感谢您的回复。
谢谢
【问题讨论】: