您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源單元測(cè)試工具 > junit
junit淺學(xué)筆記二
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/12/26 10:03:21 ] 推薦標(biāo)簽:軟件測(cè)試 開(kāi)源

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

*             @ Test:測(cè)試方法

                 A) (expected=XXEception.class)

                B) (timeout=xxx)

*.           @ Ignore:被忽略的測(cè)試方法

*.           @Before:每一個(gè)測(cè)試方法之前云行。

*.           @After :每一個(gè)測(cè)試方法之后運(yùn)行。

*.           @BefreClass所有測(cè)試開(kāi)始之前運(yùn)行。

*.           @AfterClass所有測(cè)試結(jié)果之后運(yùn)行。

下面通過(guò)一個(gè)測(cè)試程序來(lái)解釋這些注解含義

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//的所有方法運(yùn)行之前運(yùn)行。
publicstaticvoidbeforeClass(){
System.out.println("------------beforeClass");
}

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

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

@After//每個(gè)測(cè)試方法運(yùn)行之后運(yùn)行
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");

}

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