软件测试实验一

实验报告

a) The brief description that I install junit, hamcrest and eclemma.

Junit,hamcrest

上网下载junit,hamrest包,然后在项目中新建文件夹lib,复制包到其中,然后单击项目->build path -> configer build path,然后在把包加入,如图

 Eclemma

解压 eclemma压缩包,将其复制于eclipse->dropins文件夹下。删除META-INF文件夹。

b) The test result and coverage report (print screen) of your tests on triangle problem. 

代码:

package homeWork1;

public class Triangle {
public boolean lengthTest(int a , int b, int c){
if ( a + b > c && a + c > b && b + c > a){
return true;
}else{
return false;
}
}
public boolean isPositive(int a , int b , int c){
boolean ans = true;
if (a <= 0 || b <= 0 || c <=0 ){
ans = false;
//System.out.println("The number of edge must be a positive number");
}
return ans;
}
public boolean isTriangle(int a, int b , int c){
if(isPositive(a,b,c)){
if(lengthTest(a,b,c)){

return true;
}else{
//System.out.println("It can't be a triangle.");
return false;
}
}else{
return false;
}


}
public String function(int a, int b, int c){
if(isTriangle(a,b,c)){
if (a == b && b == c){

return "equilateral";
}else if(a == b || b == c || a == c){

return "isosceles";
}else{

return "scalene";
}
}else{
return "noTriangle";
}
}

}

测试代码;

package homeWork1;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TriangleTest {

Triangle t1 = new Triangle();
public void test(){
assertEquals("noTriangle",t1.function(-1, 2, 3));
assertEquals("noTriangle",t1.function(1, 2, 3));
assertEquals("noTriangle",t1.function(8, 2, 3));
assertEquals("equilateral",t1.function(3, 3, 3));
assertEquals("isosceles",t1.function(3, 3, 2));
assertEquals("scalene",t1.function(3, 4, 2));
}
public static void main(String[] args) {
TriangleTest t2 = new TriangleTest();
t2.test();
}
}

 

覆盖结果:

 

posted @ 2018-03-25 22:21  capslock1  阅读(116)  评论(0编辑  收藏  举报