使用test注解
1、配置環境
選中java工程 -> 滑鼠右擊 ->properties -> Java Build Path - > Libraries -> Add Library -> JUnit 添加完成後就可以在方法上使用@Test注解了。

2、運作:
1、點選左上角的運作按鈕是運作所有的測試方法
2,在某個測試方法名上右擊->Run As —>Junit Test 是運作該測試方法,其他的不運作。
或者在選中方法的時候,直接點選運作按鈕。
注意:方法權限隻能是public,不能用static修飾。
3、@Before注解可以完成@Test方法前的屬性初始化等操作。
public class TestCls {
int a =0;
@Before
public void init(){
a = 10;
}
@Test
public void test (){
System.out.println("a is :"+a);
}
@Test
public void tets0(){
System.out.println("test0");
}