您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
junit淺學筆記二
作者:網絡轉載 發(fā)布時間:[ 2013/12/26 10:03:21 ] 推薦標簽:軟件測試 開源

2.  下面介紹junit4 的常用注解

*             @ Test:測試方法

                 A) (expected=XXEception.class)

                B) (timeout=xxx)

*.           @ Ignore:被忽略的測試方法

*.           @Before:每一個測試方法之前云行。

*.           @After :每一個測試方法之后運行。

*.           @BefreClass所有測試開始之前運行。

*.           @AfterClass所有測試結果之后運行。

下面通過一個測試程序來解釋這些注解含義

packagecom.junit4.cc.test;

importstaticorg.junit.Assert.*;
importstaticorg.hamcrest.Matcher.*;

importorg.junit.Test;
importcom.junit4.cc.*;

importorg.junit.Before;
importorg.junit.BeforeClass;
importorg.junit.AfterClass;
importorg.junit.After;
importorg.junit.Ignore;

publicclassTTest {

@BeforeClass//的所有方法運行之前運行。
publicstaticvoidbeforeClass(){
System.out.println("------------beforeClass");
}

@AfterClass//在所有方法運行之后運行
publicstaticvoidafterClass(){
System.out.println("-------------afterClass");
}

@Before//每個測試方法運行之前運行
publicvoidbefore(){
System.out.println("=======before");
}

@After//每個測試方法運行之后運行
publicvoidafter(){
System.out.println("=======after");
}

@Test
publicvoidtestAdd() {
intz=newT().add(5,3);
assertEquals(8,z);
System.out.println("test Run through");
}

@Test ()
publicvoidtestdivision(){
System.out.println("in Test Division");

}

上一頁123下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd