软件测试作业3
a. Draw the control flow graph for the printPrimes() method.

b. Consider test cases t1=(n=3) and t2=(n=5).Although these tour the same prime paths in printPrimes(), they do not necessarily find the same faults. Design a simple fault that t2 would be more likely to discover than t1 would.
Answer: t2 更容易发生数组越界错误。
c. For printPrimes(),find a test case such that the corresponding test path visits the edge that connects the beginning of the while statement to the for statement without going through the body of the while loop.
Answer: 取测试用例n=1.
d.Enumerate the test requirements for node coverage, edge coverage, and prime path coverage for the graph for printPrimes().
node coverage: {1,2,3,4,5,6,7,8,9,10,11,12,13}
edge coverge: {(1,2),(2,3),(3,4),(4,5),(4,8),(5,6),(6,4),(5,7),(7,8),(8,9),(8,2),(9,2),(2,10),(10,11),(11,12),(12,11),(11,13)}
prime path coverage: {(1,2,3,4,5,6),(1,2,3,4,5,7,8),(1,2,3,4,5,7,8,9),(1,2,3,4,8),(1,2,3,4,8,9),(1,2,10,11,13),(1,2,10,11,12),(4,5,6,4),(5,6,4,5),(6,4,5,6),(6,4,8),(6,4,8,9),(11,12,11),(12,11,12),(12,11,13),(2,3,4,8,2),(2,3,4,5,7,8,2),(2,3,4,8,9,2),(2,3,4,5,7,8,9,2)}
主路径覆盖测试
import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class PrintPrimesTest { private PrintPrimes pptest; @Before public void setUp() throws Exception { test = new PrintPrimes(); } @Test public void testPrintPrimes() { test.printPrimes(5); } }

浙公网安备 33010602011771号