软件测试,Homework3

软件测试,Homework3

题目

private 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 primes.

        // 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; i++ ) {
                //for each previous prime.
                if(isDvisible(primes[i],curPrime)) {
                    //Found a divisor, curPrime is not prime.
                    isPrime = false;
                    break;
                }
            }
            if(isPrime) {
                // save it!
                primes[numPrimes] = curPrime;
                numPrimes++;

            }
        }// End while

        // print all the primes out
        for(int i = 0; i < numPrimes; i++) {
            System.out.println("Prime: " + primes[i] );

        }

    }// End printPrimes.
  • 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.
  • 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.
  • d)Enumerate the test requirements for node coverage, edge coverage, and prime path coverage for the graph for printPrimes().

解答

The control flow graph

Design a simple fault

MAXPRIMES = 4 的时候,test case t2 会发生数组越界,而test case t1 不会。

Find the test case

test case t3 = (n = 1)

Node coverage, edge coverage, and prime path coverage for the graph

  • Node coverage

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

Test Paths: [1,2,3,4,5,6,7,5,6,8,9,10,2,11,12,13,14,15]

  • Edge coverage

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

Test Paths: [1, 2, 3, 4, 5, 6, 7, 5, 6, 8, 9, 10, 2, 11, 12, 13, 14, 12, 15 ], [1, 2, 3, 4, 5, 9, 2, 11, 12, 15 ]

  • Prime Path coverage

TR = {[5,6,7,5] , [6,7,5,6] , [7,5,6,7] , [12,13,14,12] , [13,14,12,13] , [13,14,12,15] , [14,12,13,14] ,

[1,2,11,12,15] ,

[2,3,4,5,6,7] , [2,3,4,5,9,2] , [3,4,5,9,2,3] , [4,5,9,2,3,4] , [5,9,2,3,4,5] , [9,2,3,4,5,9] ,

[1,2,3,4,5,6,7] , [1,2,3,4,5,9,10] , [1,2,11,12,13,14,15] , [2,3,4,5,9,10,2] , [3,4,5,9,10,2,3] , [4,5,9,10,2,3,4] , [5,9,10,2,3,4,5] , [9,10,2,3,4,5,9] , [10,2,3,4,5,9,10] ,

[1,2,11,12,13,14,12,15] , [2,3,4,5,6,8,9,2] , [3,4,5,6,8,9,2,3] , [3,4,5,9,2,11,12,15] , [4,5,6,8,9,2,3,4] , [5,6,8,9,2,3,4,5] , [6,7,5,9,2,11,12,15] , [6,8,9,2,3,4,5,6] ,

[8,9,2,3,4,5,6,8] , [9,2,3,4,5,6,8,9] ,

[1,2,3,4,5,6,8,9,10] , [2,3,4,5,6,8,9,10,2] , [3,4,5,6,8,9,10,2,3] , [3,4,5,9,10,2,11,12,15] , [4,5,6,8,9,10,2,3,4] , [5,6,8,9,10,2,3,4,5] , [6,7,5,9,10,2,11,12,15] ,

[6,8,9,10,2,3,4,5,6] , [8,9,10,2,3,4,5,6,8] , [9,10,2,3,4,5,6,8,9] , [10,2,3,4,5,6,8,9,10] ,

[3,4,5,6,8,9,10,11,12,15] ,

[3,4,5,6,8,9,10,2,11,12,15] , [3,4,5,9,2,11,12,13,14,12,15] , [6,7,5,9,2,11,12,13,14,12,15] ,

[3,4,5,9,10,2,11,12,13,14,12,15] , [6,7,5,9,10,2,11,12,13,14,12,15] ,

[3,4,5,6,8,9,2,11,12,13,14,12,15] ,

[3,4,5,6,8,9,10,2,11,12,13,14,12,15]}

Test Paths: [ 1, 2, 11, 12, 15 ]

[ 1, 2, 11, 12, 13, 14, 15 ]

[ 1, 2, 11, 12, 13, 14, 12, 15 ]

[ 1, 2, 3, 4, 5, 6, 7, 5, 6, 7, 5, 6, 8, 9, 2, 3, 4, 5, 9, 10, 2, 3, 4, 5, 9, 2, 3, 4, 5, 9, 2, 11, 12, 13, 14, 12, 15 ]

[ 1, 2, 3, 4, 5, 9, 10, 2, 3, 4, 5, 6, 8, 9, 10, 2, 3, 4, 5, 9, 2, 11, 12, 15 ]

[ 1, 2, 3, 4, 5, 6, 8, 9, 2, 3, 4, 5, 6, 8, 9, 10, 2, 3, 4, 5, 9, 10, 2, 11, 12, 15 ]

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

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

  • 被测试类接口,Judgeinter.java
package judge;

public interface Judgeinter {

    /**
     *
     * @param a
     * @param b
     * @param c
     * @return 等边三角形;等腰三角形;普通三角形;不构成三角形
     */
    String get_re();

}
  • 被测试类, Judge.java
package judge;

public class Judge implements Judgeinter {

    int a,b,c;

    String re = "";

    public Judge(int i, int j, int k) {
        // TODO Auto-generated constructor stub
        this.a = i;
        this.b = j;
        this.c = k;
    }

    /* (non-Javadoc)
     * @see judge.Judgeinter#judgetri(int, int, int)
     */
    private int judgetri() {
        if (a+b > c && a-b < c) {
            if (a == b & b == c & c ==a ) {
                return 1;
            }else if (a == b || a == c || b == c) {
                return 2;
            }else {
                return 3;
            }
        }else {
            return -1;
        }
    }

    private void set_re() {
        int single = judgetri();
        if (single == 1 ) {
            re = "等边三角形";
        } else if (single == 2) {
            re = "等腰三角形";
        } else if (single == 3){
            re = "普通三角形";
        } else if (single == -1) {
            re = "不是三角形";
        } else {
            try {
                throw new Exception();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                System.out.println("错误,无法判断!");
                e.printStackTrace();
            }
        }
    }

    public String get_re() {
        set_re();
        return re;
    }

}
  • 测试类,JudgeTest.java
package judge;

public class Judge implements Judgeinter {

    int a,b,c;

    String re = "";

    public Judge(int i, int j, int k) {
        // TODO Auto-generated constructor stub
        this.a = i;
        this.b = j;
        this.c = k;
    }

    /* (non-Javadoc)
     * @see judge.Judgeinter#judgetri(int, int, int)
     */
    private int judgetri() {
        if (a+b > c && a-b < c) {
            if (a == b & b == c & c ==a ) {
                return 1;
            }else if (a == b || a == c || b == c) {
                return 2;
            }else {
                return 3;
            }
        }else {
            return -1;
        }
    }

    private void set_re() {
        int single = judgetri();
        if (single == 1 ) {
            re = "等边三角形";
        } else if (single == 2) {
            re = "等腰三角形";
        } else if (single == 3){
            re = "普通三角形";
        } else if (single == -1) {
            re = "不是三角形";
        } else {
            try {
                throw new Exception();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                System.out.println("错误,无法判断!");
                e.printStackTrace();
            }
        }
    }

    public String get_re() {
        set_re();
        return re;
    }

}
JudgeTest.java
package Test;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import judge.Judge;

class JudgeTest {

    @BeforeEach
    void setUp() throws Exception {
        System.out.println("测试开始");
    }

    @Test
    void test1() {
        Judge judge = new Judge(3,2,5);
        String  result = judge.get_re();
        System.out.println(result);
        assertEquals("不是三角形",result);
    }

    @Test
    void test2() {
        Judge judge = new Judge(2,3,4);
        String  result = judge.get_re();
        System.out.println(result);
        assertEquals("普通三角形",result);
    }

    @Test
    void test3() {
        Judge judge = new Judge(5,5,3);
        String  result = judge.get_re();
        System.out.println(result);
        assertEquals("等腰三角形",result);
    }

    @Test
    void test4() {
        Judge judge = new Judge(6,6,6);
        String  result = judge.get_re();
        System.out.println(result);
        assertEquals("等边三角形",result);
    }

    @Test
    void test5() {
        Judge judge = new Judge(4,2,3);
        String  result = judge.get_re();
        System.out.println(result);
        assertEquals("不是三角形",result);
    }

}
  • 结果。

原文地址:https://www.cnblogs.com/sunpengfei/p/8652965.html

时间: 2024-10-07 01:42:23

软件测试,Homework3的相关文章

软件测试homework3

题目:课本49页7题a)b)c)d) 解答如下: a)PrintPrimes()方法的控制流图如下: b)例如MAXPRIMES=4时,t2=(n=5)会出现数组越界的问题. c)n=1时会出现. d)节点覆盖:{0,1,2,3,4,5,6,7,8,9,10,11,12,13} 边覆盖:{(0,1),(1,2),(1,10),(2,3),(3,4),(3,7),(4,5),(4,6),(5,7),(6,3),(7,8),(7,9),(8,9),(9,1),(10,11),            

软件测试homework3的主路径覆盖

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 ;

软件测试概述

• 不论软件的生产者还是软件的使用者,均生存在竞争的环境中: 软件开发商为了占有市场,必须把产品质量作为企业的重要目标之一,以免在激烈的竞争中被淘汰出局. 用户为了保证自己业务的顺利完成,当然希望选用优质的软件. 软件带来错误的原因很多,具体地说,主要有如下几点: • 交流不够.交流上有误解或者根本不进行交流 • 软件复杂性 • 程序设计错误 • 需求变化 • 时间压力 • 代码文档贫乏 • 软件开发工具 什么是软件测试 软件测试就是在软件投入运行前,对软件需求分析.设计规格说明和编码的最终复审

软件测试——Peer Review

一.什么是peer review peer review是一种通过作者的同行来确认缺陷和需要变更区域的检查方法.需要进行同行评审的特定产品在定义项目软件过程的时候被确定并且作为软件开发计划的一部分被安排的进度. 二.背景 这周三老师在课上安排了peer review,每5-6个人一个小组,自己进行分工,并对样例软件进行peer review. 三.peer review的图解及分工 Moderator (主持人) 主持人的主要职责,在评审会前负责正规技术评审计划和会前准备的检查:在评审会中负责调

软件测试不再黑盒— threadingtest带来第二代白盒覆盖率技术

软件测试不再黑盒- threadingtest带来第二代白盒覆盖率技术 穿线测试对于测试界的一个重大创新在于,在白盒测试理论出现数十年以后,上海零一拼装信息技术有限公司结合在测试理论方面十余年的潜心研究,率先提出了第二代覆盖率技术,这绝对不是一个口号,而是ZOA真正对于白盒测试的理解以及对于标准第三方测试服务的深度理解经过数年的基础研究以及2年有余的研发而推出的达到商用标准的技术.现在先让我们温习下经典的测试理论: 1.测试方法论 黑盒功能测试法 黑盒功能测试法, 是把要测试的软件看成一个 "黑

[ 测试思维 ] 探索式软件测试

非常不错的关于探索式软件测试的学习资料 1.探索式测试简析 作者:微软 史亮 http://pan.baidu.com/s/1c2D4tAo 2.探索式测试白皮书 作者:淘宝 季哥 http://pan.baidu.com/s/1qYFNG3y

软件测试的方法-------基于直觉和经验的方法

定义:基于直觉和经验的测试方法,不是严格意义上的科学测试方法,带有一定的随机性,测试结果不够可靠,甚至可以看作是没有办法的办法.但是,软件测试是具有社会性,呈现一定的不确定性.这时,采用直觉和经验往往能够发挥更好的作用.   1.Ad-hoc测试方法和ALAC测试 1.1.自由测试(Ad-hoc Testing)强调测试人员根据自己的经验,不受测试用例的束缚,放开思路.灵活地进行各种测试. 1.2.ALAC,是Act-like-a-customer(像客户那样做)的简写,是一种基于客户使用产品的

软件测试

一个团队在做一个软件的时候,必定离不开软件的测试,首先就是找出代码的Bug,也就是软件的错误.缺陷.Bug也可以分解为症状.程序错误.和根本原因.症状即是从用户的角度看,软件出了什么问题.程序错误乃是从代码的角度看,代码的什么错误导致了软件的问题.根本原因,错误的根源,即导致代码错误的根本原因.另外,我们测试设计游两类方法:黑箱和白箱,所谓黑箱/白箱就是指软件测试设计的方法,不是软件测试的方法.黑箱指的是在设计测试的过程中,把软件系统当作一个"黑箱",无法了解或使用系统的内部结构及知识

软件测试笔记(一)理论篇

有句话是这么说的:能动手就别哔哔,尤其是在工作节奏堪比跑马的今天,大家都推崇实干精神,能解决问题就好,去他的理论.但是无可否认的是,良好的理论素养无论是解决工作中遇到的问题,还是未来的职业发展,都帮助甚大.本文整理汇总了软件测试行业中常见的一些测试理论,供大家参考. 1.软件测试按照测试分类有:黑盒测试和白盒测试. 黑盒测试 黑盒测试也称功能测试,它是通过测试来检测每个功能是否都能正常使用.在测试中,把程序看作一个不能打开的黑盒子,在完全不考虑程序内部结构和内部特性的情况下,在程序接口进行测试,