Lab1_3015218122_戎达
一、 junit, hamcrest and eclemma的安装和使用
1.在工程中新建lib文件夹,并且将junit和hamcrest的jar包复制进去

2.右击刚刚加入的两个jar包,点击Build Path——>Add to Build Path,然后在Reference Library中会出现刚刚加入的两个jar包

3. 点击Eclipse中的Help -- Eclipse Marketspace,搜索Eclemma,点击Install即可。安装完毕后Eclipse会多出Coverage的执行图标

二、 程序代码和测试结果
被测试程序:
package test_case;
public class test_case {
public String triangle(int a,int b,int c){
if((a+b>c)&&(a+c>b)&&(b+c>a)&&(a>0)&&(b>0)&&(c>0)){
if((a==b)&&(b==c)){
System.out.println("equilateral");
return "equilateral";
}
else if((a==b)||(b==c)||(a==c)){
System.out.println("isoscele");
return "isoscele";
}
else System.out.println("scalene");
return "scalene";
}
else System.out.println("not a triangle");
return "not a triangle";
}
}
测试程序:
package test;
import org.junit.Test;
import junit.framework.Assert;
import test_case.test_case;
public class test {
@Test
public void testtriangle(){
test_case at=new test_case();
Assert.assertEquals("equilateral",at.triangle(3, 3, 3));
Assert.assertEquals("isoscele",at.triangle(3, 3, 2));
Assert.assertEquals("not a triangle", at.triangle(1, 3, 4));
}
}
测试结果:


浙公网安备 33010602011771号