软件测试实验1
软件测试实验1
3015218139_白春赞
1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
下载junit,hamcrest
在工程下面新建文件lib,将junit,hamcrest copy到文件夹中,然后右键点击Build Path-Add Extend Archives
2. Install Eclemma with Eclipse
将eclemma压缩包下载下来后解压到Eclipse本地目录的dropins下,重启Eclipse即可:
重启后,eclipse上面出现如下标志,则插件安装成功
3. 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.
triangle.java
package cn.tju.scs; public class triangle { public triangle(){} public String triangles(int a, int b, int c) { if(a + b > c && a + c > b && b + c > a) { if(a == b && b == c) return "equilateral"; else if(a == b || b == c || a == c) return "isosceles"; else { return "scalene"; } } else { return "Non-triangular"; } } }
testtriangle.java
package cn.tju.scs; import static org.junit.Assert.*; import static org.hamcrest.Matchers.*; import org.junit.Before; import org.junit.Test; public class testtriangle { public triangle tr = new triangle(); @Before public void setUp() throws Exception { } @Test public void testTrangle() { assertEquals("equilateral", tr.triangles(3, 3, 3)); assertEquals("isosceles", tr.triangles(3, 2, 2)); assertEquals("scalene", tr.triangles(3, 4, 2)); assertEquals("Non-triangular", tr.triangles(2, 2, 4)); } }
结果如下: