博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
软件测试-HW03
阅读量:5167 次
发布时间:2019-06-13

本文共 2757 字,大约阅读时间需要 9 分钟。

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

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

  

   (b) Considertestcasest1=(n=3)andt2=(n=5).Although these tourthe same prime paths in printPrimes(), they do not necessarily find      the same faults.Designasimplefaultthat t2 would bemorelikelytodiscover than t1 would.

    将变量MAXPRIMES设为4时,t2会发生数组越界错误,但t1不会。

     

   (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.

     当n = 1时,运行时会从第2个节点直接跳转到第12个节点,不经过while语句的循环体

   

   (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, 14, 15, 16}

     Edge Coverage:{(1,2),(2,3),(3,4),(4,5),(5,6),(6,8),(8,5),(6,7),(7,9),(5,9),(9,10),

             (9,11),(10,11),(11,2),(2,12),(12,13),(13,14),(14,15),(15,13),(13,16)}

     MPC:{(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)}

二.基于Junit及Eclemma(jacoco)实现一个主路径覆盖的测试。

  测试代码:

package test;public class test {    void printPrimes(int n){        int curPrime;        int numPrimes;        boolean isPrime;        int [] primes = new int [43];        primes[0]=2;        numPrimes = 1;        curPrime = 2;        while ( numPrimes < n)        {            curPrime ++ ;            isPrime = true;            for ( int i = 0 ; i <= numPrimes-1 ;i++){                if (isDivisible(primes[i],curPrime))                {                    isPrime = false;                    break ;                }            }            if (isPrime){                primes[numPrimes] = curPrime ;                numPrimes ++ ;                            }        }                for (int i = 0 ; i <= numPrimes -1 ; i++ )        {            System.out.println("Prime: " + primes[i]);        }            }    boolean isDivisible(int i, int curPrime) {        if ( curPrime % i == 0 )            return true;        return false;    }}

  

package test;import static org.junit.Assert.*;import org.junit.Before;import org.junit.Test;public class testTest {    private test t= null;    @Before    public void setUp() throws Exception {        t = new test ();    }    @Test    public void test() {        t.printPrimes(0);        t.printPrimes(3);        t.printPrimes(5);    }}

  测试结果:

  

 使用EclEmma 进行覆盖测试:

 

转载于:https://www.cnblogs.com/cheetah666/p/6545431.html

你可能感兴趣的文章
[Spring框架]Spring 事务管理基础入门总结.
查看>>
2017.3.24上午
查看>>
Python-常用模块及简单的案列
查看>>
LeetCode 159. Longest Substring with At Most Two Distinct Characters
查看>>
基本算法概论
查看>>
jquery动态移除/增加onclick属性详解
查看>>
JavaScript---Promise
查看>>
暖暖的感动
查看>>
Java中的日期和时间
查看>>
Django基于admin的stark组件创建(一)
查看>>
C. Tanya and Toys_模拟
查看>>
springboot jar包运行中获取资源文件
查看>>
基于FPGA实现的高速串行交换模块实现方法研究
查看>>
Java Scala获取所有注解的类信息
查看>>
delphi ,安装插件
查看>>
case when then的用法-leetcode交换工资
查看>>
11.28.cookie
查看>>
BeanShell简介
查看>>
python字符串操作
查看>>
不同程序语言的注释和变量要求
查看>>