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

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

  任務一,Install Junit(4.12), Hamcrest(1.3) with Eclipse
  首先在網上下載Junit和Hamcrest的jar文件,Right click on the project root directory - > build path - > configure build path - > library the junit. Jar, hamcrest. Jar added
  任務二,Install Eclemma with Eclipse
  在myeclipse頂部菜單欄中 help->install from catalog,在搜索欄中輸入Eclemma,點擊安裝,一步步按照提示,即可完成安裝
  任務三,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,點擊左上角的File,新建一個Java project,命名為hello,然后在src目錄下新建兩個包,分別命名為hw1和test。
  在hw1中新建一個class,命名為exp.java.
  在exp.java中輸入如下代碼:

  然后右擊exp.java,在選項new里面點擊JUnit Test Case,點擊next。
  新建了expTest.java后,將兩個方法里面的“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) //這是一個參數化的測試類
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   //在運行之前先運行這個函數
public void setUp(){
tr=new exp();
}
@Parameters  //給構造函數參數初始化
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函數
public void testTrian(){
assertEquals(this.expected,tr.trian(a,b,c));
}
}
  保存后,右擊expTest.java,選擇Run As,再選擇Junit Test,即可運行junit,測試在ScoreTest.java里面的數據是否正確。如圖,測試結果通過則顯示綠條,否則顯示紅條,可以根據提示找到錯誤所在

  測試正確,使用junit進行程序測試,會發現非常方便,很容易找到哪里出錯。

軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: www.一级毛片| 久久91亚洲精品中文字幕 | 永久免费看www色视频 | 免费看大黄高清网站视频在线 | 欧美日韩亚洲另类 | 91在线 在线播放 | 日本高清www午色夜黄 | 日本三级在在线观看 | 99爱视频99爱在线观看免费 | 一级毛片aaaaaa视频免费看 | 午夜精品久视频在线观看 | 在线看福利片 | a黄网站| 日本免费一区二区三区看片 | 成人无遮挡免费网站视频在线观看 | 日韩精品欧美激情亚洲综合 | 日本一区二区三区免费在线观看 | 91视频免费网站 | 两个人看的www高清免费视频 | 怡红院免费的全部视频 | 欧美很黄视频在线观看 | 好吊色几万部永久免费视频 | www.青青草.com | 婷婷综合激情 | 簧片免费视频 | 国产真实乱偷人视频 | 欧美片欧美日韩国产综合片 | 青青草国产成人久久91网 | 亚洲一级特黄 | 久久天天躁夜夜躁狠狠躁2015 | 韩国伦理片中文字幕 | 91亚洲国产成人久久精品网站 | 欧美乱一级在线观看 | 高清三级毛片 | 看黄在线 | 国产综合视频 | 国产精品麻豆一区二区 | 最近中文字幕完整视频高清1 | 99热手机在线观看 | aaa国产一级毛片 | bl男男全肉高h集合 bl男男全肉高h车 |