欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

软件测试作业

程序员文章站 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));
	}

}

测试结果如下:
软件测试作业