日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

junit 4學(xué)習(xí)

系統(tǒng) 1681 0
?? JUNIT 4中,有幾個(gè)地方要注意一下的,歸納之
1

@Test (expected=ArithmeticException. class )?

public ? void ?testDivide()?{ ??

????assertEquals( 3 ,Math.divide( 9 , 3 ));???
???Math.divide( 10 , 0 );? //除數(shù)不能為0,會(huì)拋出異常? ??
??
} ??
? junit4中不用try catach了,用這樣聲明 “@Test(expected=ArithmeticException.class)”Junit4 就會(huì)檢查此方法是否拋出ArithmeticException異常,
2)
?? 套件方面
??

import ?org.junit.runner.RunWith; ??

import ?org.junit.runners.Suite; ??

import ?org.junit.runners.Suite.SuiteClasses; ??

@RunWith (Suite. class ) ??

@SuiteClasses ({a. class , ??

????????b. class }) ??

?? public ? class ?Util4Suite?{ ??

}??
則a,b兩個(gè)類都要運(yùn)行測(cè)試

3) 參數(shù)化測(cè)試
?? import ? static ?org.junit.Assert.assertEquals;

import ?org.junit.Test;

import ?org.junit.runner.RunWith;

import ?org.junit.runners.Parameterized;

import ?org.junit.runners.Parameterized.Parameters;

?

import ?java.util.Arrays;

import ?java.util.Collection;

?

@RunWith(Parameterized.
class )

public ? class ?SquareTest? ... {

?

????
private ? static ?Calculator?calculator? = ? new ?Calculator();

????
private ? int ?param;

????
private ? int ?result;

?

????@Parameters

????
public ? static ?Collection?data()? ... {

????????
return ?Arrays.asList( new ?Object[][] ... {

????????????????
... { 2 ,? 4 } ,

????????????????
... { 0 ,? 0 } ,

????????????????
... {- 3 ,? 9 } ,

????????}
);

????}


?

?

// 構(gòu)造函數(shù),對(duì)變量進(jìn)行初始化

????
public ?SquareTest( int ?param,? int ?result)? ... {

????????
this .param? = ?param;

????????
this .result? = ?result;

????}


?

????@Test

????
public ? void ?square()? ... {

????????calculator.square(param);

????????assertEquals(result,?calculator.getResult());

????}


?

}



junit 4學(xué)習(xí)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 砀山县| 通化市| 花莲县| 东兴市| 溧阳市| 新竹市| 镇宁| 吴江市| 黑龙江省| 扎赉特旗| 新巴尔虎左旗| 苍溪县| 普陀区| 寻乌县| 南和县| 来宾市| 广昌县| 澜沧| 绍兴县| 咸阳市| 松阳县| 尉氏县| 安岳县| 鄂州市| 清水县| 河北区| 连云港市| 光山县| 宣化县| 尼勒克县| 松溪县| 莒南县| 古田县| 盐山县| 南丹县| 固阳县| 古交市| 丰城市| 玉环县| 喜德县| 油尖旺区|