亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Eclipes使用Junit進(jìn)行測試
作者:陌然之始 發(fā)布時(shí)間:[ 2017/3/23 17:03:00 ] 推薦標(biāo)簽:單元測試 Junit

  任務(wù)一,Install Junit(4.12), Hamcrest(1.3) with Eclipse
  首先在網(wǎng)上下載Junit和Hamcrest的jar文件,Right click on the project root directory - > build path - > configure build path - > library the junit. Jar, hamcrest. Jar added
  任務(wù)二,Install Eclemma with Eclipse
  在myeclipse頂部菜單欄中 help->install from catalog,在搜索欄中輸入Eclemma,點(diǎn)擊安裝,一步步按照提示,即可完成安裝
  任務(wù)三,Write a java program for the triangle problem and test the program with Junit.
  a) Description of triangle problem:
Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.
progran:
package hw1;
public class exp {
public int trian(int a,int b,int c){
if((a==b)&&(a==c)&&(b==c)){  //等邊三角形
return 0;
}
else if((a != b)&&(a!=c)&&(b!=c)){  //不等邊三角形
return 1;
}
else{
return 2;      //等腰三角形
}
}
}
  b)Using junit test
  打開eclipse,點(diǎn)擊左上角的File,新建一個(gè)Java project,命名為hello,然后在src目錄下新建兩個(gè)包,分別命名為hw1和test。
  在hw1中新建一個(gè)class,命名為exp.java.
  在exp.java中輸入如下代碼:

  然后右擊exp.java,在選項(xiàng)new里面點(diǎn)擊JUnit Test Case,點(diǎn)擊next。
  新建了expTest.java后,將兩個(gè)方法里面的“fail("Not yet implemented");”刪去,加入如下代碼:
package test;
import java.util.Arrays;
import java.util.Collection;
import org.junit.*;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import hw1.exp;
import static org.junit.Assert.*;
@RunWith(Parameterized.class) //這是一個(gè)參數(shù)化的測試類
public class expTest {
private exp tr;
private int a,b,c,expected;
public expTest(int a,int b,int c,int expected){
this.a=a;
this.b=b;
this.c=c;
this.expected=expected;
}
@Before   //在運(yùn)行之前先運(yùn)行這個(gè)函數(shù)
public void setUp(){
tr=new exp();
}
@Parameters  //給構(gòu)造函數(shù)參數(shù)初始化
public static Collection<Object[]> getData(){
return Arrays.asList(new Object[][]{
{1,2,3,1},
{2,2,2,0},
{2,2,3,2},
{2,3,4,1}
});
}
@Test     //測試Train函數(shù)
public void testTrian(){
assertEquals(this.expected,tr.trian(a,b,c));
}
}
  保存后,右擊expTest.java,選擇Run As,再選擇Junit Test,即可運(yùn)行junit,測試在ScoreTest.java里面的數(shù)據(jù)是否正確。如圖,測試結(jié)果通過則顯示綠條,否則顯示紅條,可以根據(jù)提示找到錯(cuò)誤所在

  測試正確,使用junit進(jìn)行程序測試,會(huì)發(fā)現(xiàn)非常方便,很容易找到哪里出錯(cuò)。

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 丁香婷婷激情五月 | 91嫩草国产在线观看免费 | 国产一区国产二区国产三区 | 久久精品国产一区二区三区不卡 | 色淫影院 | 黄色国产在线观看 | 亚洲精品视频导航 | 日韩 欧美 综合 在线 制服 | 色一情一乱一伦一区二区三区 | 日韩中文字幕在线观看 | 日韩中文字幕精品免费一区 | 男人下面桶女人视频免费 | 奇米777狠狠色噜噜狠狠狠 | 97人人做人人爽人人喊 | 欧美成人三级网站在线观看 | 午夜免费理论片在线看 | 黑人极品videos精品欧美裸 | 黄色3级视频 | 69堂午夜精品视频在线 | 国产精品欧美日韩精品 | 天天做天天爱天天做天天吃中 | 深夜福利在线免费观看 | 亚洲国产精品v在线播放 | 国产色婷婷精品免费视频 | 天天弄天天操 | 99久久精品国产一区二区 | 天堂资源在线播放 | 99精品在线免费 | 青青草国拍 | 全网毛片| 一级a性色生活片毛片 | 久久精品国产欧美成人 | 福利社午夜剧场 | 99re免费 | 欧美在线播放成人a | 亚洲午夜精品久久久久久抢 | 亚洲日本aⅴ片在线观看香蕉 | 欧美高清xxxxbbbbd | 你懂的视频在线观看 | 天天爱天天色天天干 | 日本韩国一区二区 |