软件测试assignment3
这周的作业题目
/******************************************************* * Finds and prints n prime integers * Jeff Offutt, Spring 2003 ******************************************************/ public static void printPrimes (int n) { int curPrime; // Value currently considered for primeness int numPrimes; // Number of primes found so far. boolean isPrime; // Is curPrime prime? int [] primes = new int [MAXPRIMES]; // The list of prime numbers. // Initialize 2 into the list of primes. primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; // next number to consider ... isPrime = true; for (int i = 0; i <= numPrimes-1; i++) { // for each previous prime. if (curPrime%primes[i]==0) { // Found a divisor, curPrime is not prime. isPrime = false; break; // out of loop through primes. } } if (isPrime) { // save it! primes[numPrimes] = curPrime; numPrimes++; } } // End while // Print all the primes out. for (int i = 0; i <= numPrimes-1; i++) { System.out.println ("Prime: " + primes[i]); } } // end printPrimes
一、画出控制流图
二、设计一个t2=(n=5)比t1=(n=3)容易发现发现的错误
数组越界的错误。
三、写一个测试用例,使相应的测试路径访问连接while语句开始到fot语句得边,而不用通过while的循环体
t:n=1
四、例举每个节点覆盖,边覆盖和主路径覆盖的TR
节点覆盖需求:{1,2,3,4,5,6,7,8,9,10,11,12,13}
边覆盖需求:{(1,2),(2,3),(2,10),(3,4),(4,5),(4,8),(5,6),(5,7),(6,8),(7,4),(8,2),(8,9),(9,2),(10,11),(11,12),(11,13),(12,11)}
主路径覆盖需求:
{
(4,5,6,4)
(6,4,5,6)
(5,6,4,5)
(5,6,4,,8,,2,3)
(5,6,4,8,2,10,11,12,11)
(5,6,4,8,2,10,11,13)
(3,4,5,7,8,9,2,3)
(3,4,5,7,8,2,3)
(3,4,8,9,2,3)
(3,4,8,2,3)
(3,4,5,7,8,9,2,10,11,12)
(3,4,5,7,8,9,2,10,11,13)
(3,4,5,7,8,2,10,11,12)
(3,4,5,7,8,2,10,11,13)
(3,4,8,2,10,11,13)
(3,4,8,2,10,11,12)
(4,5,7,8,9,2,3,4)
(4,5,7,8,2,3,4)
(4,8,9,2,3,4)
(4,8,2,3,4)
(1,2,3,4,8)
(1,2,3,4,5,6)
(1,2,3,4,5,7,8,9)
(1,2,10,11,12)
(1,2,10,11,13)
(11,12,11)
(12,11,12)
(12,11,13)
}
五、实现一个主路径覆盖的测试
还是使用三角形判断的程序,被测试的类为:
public class Hello { public int a; public int b; public int c; public Hello(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } public String judge() { if(a==b&&b==c) return "equilateral"; else if(a==b||b==c||c==a) return "isosceles"; else { return "scalene"; } } }
测试类用例:
import org.junit.Test; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; public class TestHello { Hello tri =null; @Before public void setUp() throws Exception { //System.out.println("This is before test"); } @After public void tearDown() throws Exception { System.out.println("This is after test"); } @Test public void test() { tri = new Hello(3,3,3); assertEquals("equilateral",tri.judge()); tri = new Hello(2,3,3); assertEquals("isosceles",tri.judge()); tri = new Hello(3,4,5); assertEquals("scalene",tri.judge()); } }