您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Junit與Eclemma的安裝及應(yīng)用
作者:夢碎 發(fā)布時間:[ 2017/4/6 15:40:55 ] 推薦標簽:單元測試 Junit

  一、junit和hamcrest安裝及引入
  1.輸入網(wǎng)址http://junit.org/junit4/下載junit及hamcrest
  2.打開Eclipse新建一個project
  3.右鍵點擊build path 引進junit

  二、eclemma安裝
  點擊help-->Eclipse Marketplace-->在find中輸入eclemma-->install-->重啟Eclipse
  三、三角形問題及junit、hamcrest、eclemma的使用
  1、編寫三角形判斷程序
public class triangle_problem {
String triangle_juidje(double a,double b, double c){
if(a == b && a == c){
String str = new String();
str = "the trangle is equilateral";
return str;
}
if((a+b)>c &&(a+c)>b &&(b+c)>a){
if((a == b && a != c)|| (a==c && a != b) || (b == c && b != a)){
String str = new String();
str = "the trangle is isosceles";
return str;
}
if(a!=b && b!=c){
String str = new String();
str = "the trangle is scalene";
return str;
}
}
else{
String str = new String();
str = "the three edges can't make up a trangle!";
return str;
}
return null;
}
}
  2、junit類生成
  選中類-->new-->jUnit Test Case

  3、編輯junit內(nèi)容
import static org.junit.Assert.*;
import org.junit.Test;
public class triangle_problemTest {
private triangle_problem tri;
@Test
public void testequilateral() {
tri = new triangle_problem();
assertEquals("the trangle is equilateral",tri.triangle_juidje(3,3,3));
}
@Test
public void testisosceles() {
tri = new triangle_problem();
assertEquals("the trangle is isosceles",tri.triangle_juidje(2,3,2));
}
@Test
public void testscalene() {
tri = new triangle_problem();
assertEquals("the trangle is scalene",tri.triangle_juidje(2,3,4));
}
@Test
public void testnottrangle() {
tri = new triangle_problem();
assertEquals("the three edges can't make up a trangle!",tri.triangle_juidje(2,3,5));
}
}
  4、運行junit文件

  5、運行eclemma

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