软件测试技术第一次上机
软件测试第一次上机
王朋来
3014218072
Tasks:
- Install Junit(4.12), Hamcrest(1.3) with Eclipse
- Install Eclemma with Eclipse
- Write a java program for the triangle problem and test the program with Junit.
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.
junit,hamcrest,eclemma安装描述
JUnit,Harmcrest在新建工程的时候导入或着直接在工程中导入,Harmcrest的jar包链接
在项目中找到Build Path。将jar包路径添加到classpath中。
Eclemma可以通过eclipse的market安装,搜索Eclemma,同意安装后重启。
软件结构如下:

triangle代码如下:
package ST;
public class triangle {
public String triangle (int a, int b,int c)
{
String str;
int d=a-b;
int e=b-c;
int f=a-c;
if( d*e*f==0){
str="isoscele";
if( (a==b) && (b==c) )
str="equilateral";
}
else
str="scalene";
return str;
}
}
triangleTS代码如下:
package ST;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import ST.triangle;
import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class triangleTS {
private String type;
private int a;
private int b;
private int c;
public triangleTS(String type, int a, int b, int c){
this.type = type;
this.a = a;
this.b = b;
this.c = c;
}
@Parameters
public static Collection prepareData(){
Object[][] object = {
{"isoscele",1,1,1},
{"equilateral",2,2,3},
{"equilateral",2,3,3},
{"scalene",2,3,4}};
return Arrays.asList(object);
}
@Test
public void TestTypeOfTriangle()
{
triangle calc = new triangle ();
assertEquals (type, calc.triangle(a,b,c));
}
}
测试结果


四组样例全部通过,且代码全被覆盖
浙公网安备 33010602011771号