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

junit 4學習

系統 1782 0
?? JUNIT 4中,有幾個地方要注意一下的,歸納之
1

@Test (expected=ArithmeticException. class )?

public ? void ?testDivide()?{ ??

????assertEquals( 3 ,Math.divide( 9 , 3 ));???
???Math.divide( 10 , 0 );? //除數不能為0,會拋出異常? ??
??
} ??
? junit4中不用try catach了,用這樣聲明 “@Test(expected=ArithmeticException.class)”Junit4 就會檢查此方法是否拋出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兩個類都要運行測試

3) 參數化測試
?? 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 } ,

????????}
);

????}


?

?

// 構造函數,對變量進行初始化

????
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學習


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 昌黎县| 淅川县| 泗阳县| 湄潭县| 光泽县| 万州区| 龙门县| 大丰市| 天津市| 简阳市| 潼南县| 榆社县| 托克逊县| 桐城市| 盐池县| 工布江达县| 浦北县| 西乌珠穆沁旗| 临江市| 云和县| 遂宁市| 介休市| 饶河县| 钦州市| 常宁市| 措美县| 中西区| 综艺| 江山市| 乌拉特后旗| 若尔盖县| 高州市| 平江县| 平阴县| 依安县| 琼海市| 濮阳市| 陇西县| 崇义县| 班玛县| 神池县|