3
想,我有一个junit
测试类:如何编写动态测试案例
class MyComponentTest { private void test(File file) {...} @Test public void test1() {test("test1.txt")} @Test public void test2() {test("test2.txt")} @Test public void test3() {test("test3.txt")} }
的test
方法从file
读取输入数据,并与输入数据测试组件。
如果我更改MyComponentTest
会怎么样?
class MyComponentTest { private void test(File file) {...} @Test public void testAll() { for (String name: dir.list()) test(new File(name)) } }
现在我只有一个测试(testAll
),而不是三个测试(test1
,test2
,并test3
),因为它是以前。例如,Runner
不会识别三个分开的测试,就像它在以前版本的类中所做的那样。
我的问题是:如何让每个test
方法调用从junit
的角度单独测试一下?
[JUnit test with dynamic number of tests]的可能重复(http://stackoverflow.com/questions/358802/junit-test-with-dynamic-number-of-tests) – McDowell 2011-06-04 14:08:35