1
在下面的代碼中,ExampleTest
類包含5個測試。但是,我想使用JUNIT從ExampleTestSuite
類中僅運行其中的兩個。如何在Junit 4中自定義我的TestSuite測試?
public class ExampleTest extends TestCase {
private Example example;
public ExampleTest(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
example= new Example();
}
protected void tearDown() throws Exception {
super.tearDown();
example= null;
}
public void test1() {
}
public void test2() {
}
public void test3() {
}
public void test4() {
}
public void test5() {
}
}
這是我的代碼,下面是在JUnit 3中完成的,但是如何在JUnit版本4中完成它?
public class ExampleTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite(ExampleTestSuite.class.getName());
suite.addTest(new ExampleTest("test1"));
suite.addTest(new ExampleTest("test3"));
return (Test) suite;
}
}
之間相互轉換的兩個版本的JUnit是題外話。 Stackoverflow不是一個代碼轉換服務。如果您在重寫代碼時遇到困難,請解決您的問題中的特定問題。 – toniedzwiedz
我不是要求你轉換所有的類,我已經使用註釋做了。我只是不知道如何限制JUnit 4中的測試。 – GSDa