软件测试(3)--coverage graph

一、 Use the following method printPrimes() for questions a–d. 

a)Draw the control flow graph for the printPrimes() method.

b)Make sure the value of  MAXPRIMES equals 4, then there will be an out-of-array –bound fault when n = 5;

c)当n=1时,会通过numPrimes>=直接从上图的2节点跳转到12节点,不经过while循环体内部。

d)

TR for nc:

 {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}

TR for ec:

{(1,2),(2,3),(2,4),(3,5),(5,6),(5,7),(6,9)(6,8)(9,10),(10,5),(8,7),(7,11),(7,12),(11,13),(12,13),(13,2),(2,4),(4,15),(15,16),(16,4),(4,14)}

TR for ppc:

{(1,2,3,4,5,6,8),(1,2,3,4,5,6,7,9,10,11),(1,2,3,4,5,6,7,9,11),(1,2,3,4,5,9,11),(1,2,3,4,5,9,10,11),(5,6,8,5),(6,8,5,6),(8,5,6,8),(8,5,6,7,9,11),(8,5,6,7,9,10,11),(1,2,12,13,16),(1,2,12,13,14,15),(13,14,15,13),(14,15,13,14),(15,13,14,15),(14,15,13,16),(15,13,16)}

二、Using Junit and Eclemma to test the method and cover all prime paths above

package printPrimes;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class primeTest {

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void test() {
        prime.printPrimes(3);
    }

}

测试结果

原文地址:https://www.cnblogs.com/Reallylzl/p/6546071.html