软件测试实验报告
a) The brief description that you install junit, hamcrest and eclemma.
1.右键Triangle.java文件选择new-->Juint Test Case
2.选择finish
3.选择Help-->Eclipse Marketplace
4.find—>Eclemma并安装
b) The test result and coverage report (print screen) of your tests on triangle problem.
编写的Triangle程序如下
public class Triangle {
public boolean isTriangle(int a,int b,int c)
{
if(a<=0||b<=0||c<=0)
return false;
else if(a+b>c&&a+c>b&&b+c>a)
return true;
else return false;
}
public boolean isEquilateral(int a,int b,int c)
{
if(isTriangle(a,b,c)&&a==b&&b==c)
return true;
else return false;
}
public boolean isIsosceles(int a,int b,int c)
{
if(isTriangle(a,b,c)&&(a==b||a==c||b==c))
return true;
else return false;
}
public boolean isScalene(int a,int b,int c)
{
if(isTriangle(a,b,c)&&a!=b&&a!=c&&b!=c)
return true;
else return false;
}
}
编写的测试程序如下
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class TriangleTest {
private Triangle tri;
@Before
public void setUp() throws Exception {
tri=new Triangle();
}
@Test
public void testTriangle() {
assertEquals(true,tri.isTriangle(2, 3, 4));
assertEquals(false,tri.isTriangle(2, 2, 9));
assertEquals(false,tri.isTriangle(-1, 1, 1));
}
@Test
public void testEquilateral() {
assertEquals(true,tri.isEquilateral(3, 3, 3));
assertEquals(false,tri.isEquilateral(2, 3, 3));
assertEquals(false,tri.isEquilateral(-1, 1, 1));
assertEquals(false,tri.isEquilateral(2, 3, 4));
}
@Test
public void testIsosceles() {
assertEquals(true,tri.isIsosceles(3, 3, 3));
assertEquals(true,tri.isIsosceles(2,3,3));
assertEquals(false,tri.isIsosceles(-1, 1, 1));
assertEquals(false,tri.isIsosceles(2, 3, 4));
}
@Test
public void testScalene() {
assertEquals(false,tri.isScalene(3, 3, 3));
assertEquals(false,tri.isScalene(2, 3, 3));
assertEquals(false,tri.isScalene(-1, 1, 1));
assertEquals(true,tri.isScalene(2, 3, 4));
}
}
测试覆盖结果如下:
由测试结果可以看出来,设计的测试用例覆盖了所有的语句。