软件测试作业
程序员文章站
2022-04-10 16:58:16
...
软件测试作业
1、Question
//根据下面三角形程序,结合白盒测试用例设计技术,在Junit工具中编写对应的单元测试脚本。
package test1;
public class Triangle {
protected long A, B, C = 0;
public Triangle(long A, long B, long C) {
this.A = A;
this.B = B;
this.C = C;
}
public boolean isTriangle(Triangle tri){
boolean isTrue = false;
if((tri.A>0) &&(tri.B>0) &&(tri.C>0)) {
if((tri.A<(tri.B+tri.C)) &&(tri.B<(tri.A+tri.C))
&&(tri.C<(tri.A+tri.B)))
isTrue = true;
}
return isTrue;
}
public String isType(Triangle tri) {
String strType = "";
if (this.isTriangle(tri)) {
if (tri.A == tri.B && tri.B == tri.C)
strType = "等边三角形";
else if ((tri.A != tri.B) && (tri.B != tri.C) && (tri.A != tri.C))
strType = "不等边三角形";
else
strType = "等腰三角形";
}
return strType;
}
}
2、Solution
测试代码如下:
package test1;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TriangleTest {
Triangle triangle;
@Test
public void testIsTriangle01() {
triangle=new Triangle(1, 2, 3);
assertEquals(false, triangle.isTriangle(triangle));
}
@Test
public void testIsTriangle02() {
triangle=new Triangle(3, 4, 5);
assertEquals(true, triangle.isTriangle(triangle));
}
@Test
public void testIsTriangle03() {
triangle=new Triangle(3, 4, 5);
assertEquals(false, triangle.isTriangle(triangle));
}
@Test
public void testIsType01() {
triangle=new Triangle(2, 2, 3);
assertEquals("等腰三角形",triangle.isType(triangle));
}
@Test
public void testIsType02() {
triangle=new Triangle(1, 2, 3);
assertEquals("",triangle.isType(triangle));
}
@Test
public void testIsType03() {
triangle=new Triangle(3, 4, 5);
assertEquals("不等边三角形",triangle.isType(triangle));
}
@Test
public void testIsType04() {
triangle=new Triangle(3, 3, 3);
assertEquals("等边三角形",triangle.isType(triangle));
}
@Test
public void testIsType05() {
triangle=new Triangle(2, 1, 1);
assertEquals("等腰三角形",triangle.isType(triangle));
}
}
测试结果如下:
上一篇: 排骨加什么炖汤好喝,一招教你搭配出既美味又营养的排骨汤
下一篇: 塑造女性完美体形的瑜伽运动