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