如何添加junit框架:
右鍵項目-->build path-->add libraries --->選擇junit,然後就可以使用了
測試的方法必須是空參的,沒有返回值的方法。
public class TestJunit {
@Before
public void testBefore(){
System.out.println("before");
}
@After
public void testAfter(){
System.out.println("after");
}
public void test1(){
System.out.println("aa");
m1();//test的方法可以直接調用別的方法。
}
public void m1(){
System.out.println("m1 method");
}
}
@Before註解的方法會在每個@Test方法前執行,@after註解的方法會在每個@Testd方法後執行。