• 实验6、白盒测试:路径测试及测试用例设计


    实验6盒测试:路径测试及测试用例设计

    一、实验目的

    1、掌握控制流图,独立路径,圈复杂度,程序基本路径集的概念。

    2、掌握McCabe程序基本路径集确定方法。

    3、掌握基本路径集测试法。

    二、实验任务

    1、程序void score_processing(float score[],int length)的功能说明如下:程序统计数组score前10个元素中有效成绩([0,100]内为有效成绩)的个数、总和及平均值,并输出。参数说明:数组score内按顺序存放着n个学生成绩(n<=length),且以-1作为结束标志,length为数组的长度且length〉10。

    试用基本路径集测试法测试该程序,撰写实验报告。

    实验步骤:

    1. 画出程序的流图(控制流程图)因代码过于复杂就只画了主函数的程序流图

    1. 计算流图G的圈复杂度V(G)。

    V(G)=6(区域数)

    1. 确定只包含独立路径的基本路径集。

    ①1-2-3-4-5-15

    ②1-2-3-4-5-6-8-10-12-14-3-4-5-15

    ③1-2-3-4-5-6-7-14-3-4-5-15

    ④1-2-3-4-5-6-8-9-14-3-4-5-15

    ⑤1-2-3-4-5-6-8-10-11-14-3-4-5-15

    ⑥1-2-3-4-5-6-8-10-12-13-14-3-4-5-15

    1. 根据上面的独立路径,设计测试用例,得到测试用例表。

    通过独立路径的综合分析,只需要测试路径②即可实现所有路径覆盖,故设计测试用例如下:

    测试用例ID

    测试数据

    预期输出

    测试路径

    T1

    score[50,64,84,55,20,73,44,84,0,100,51]

    有效的个数

    前十个总和

    前十个平均值

    10

    574.0

    57.4

    T2

    score[20,100]

    \

    \

    \

    1. 执行测试,填写软件缺陷报告。
    1. T1测试与预期结果相符
    2. T2测试出现缺陷

    模块名称

    程序class Score进行软件测试

    版本号

    V1.0

    测试人

    XXX

    缺陷类型

    一般缺陷

    严重级别

    B类

    可重复性

    缺陷状态

    New

    测试平台

    Win11

    测试软件

    Interlij IDEA

    简述

    程序中未对score.length即数组长度,大于10作出限制

    操作步骤

    1. 启动程序
    2. 请输入对应数字进行操作:1
    3. 请输入要存入的成绩的数量:2

    实际结果

    请输入第1个数据:

    20

    请输入第2个数据:

    100

    预期结果

    要存入的成绩的数量小于10,请重新设置

    注释

    注释完整

    注:(2)一般的(Major)。不太严重的错误,如次要功能模块丧失、提示信息不够准确、用户界面差和操作时间长等。

    附测试代码:

    package com.shu.exer;
    import java.util.Scanner;
    public class Score {
        private float score[];
        public float[] getScore() {
            return score;
        }
        public void setScore(float[] score) {
            this.score = score;
        }

        public Score() {
        }
        public Score(float[] score) {
            this.score = score;
        }
        //统计前10个元素中有效成绩([0,100]内为有效成绩)的个数
        public int validScoreNum() {
            int num = 0;
            for(int i=0; i<10; i++) {
                if(0<=score[i] && score[i]<=100) {
                    num++;
                }
            }
            return num;
        }
        //求前十个学生的总成绩
        public float sumScore() {
            float sum = 0;
            for(int i=0; i<10; i++) {
                sum+=score[i];
            }
            return sum;
        }
        //求前十个学生成绩的平均值
        public float averScore() {
            float sum = 0;
            for(int i=0; i<10; i++) {
                sum+=score[i];
            }
            float averScore=sum/10;
            return averScore;
        }

        //显示操作菜单
        public void menu() {
           System.out.println("***************************************");
            System.out.println("       1--初始化学生成绩");
            System.out.println("       2--统计前10个学生的有效成绩([0,100]内为有效成绩)的个数");
            System.out.println("       3--统计前10个学生的总成绩");
            System.out.println("       4--统计前10个学生的平均成绩");
            System.out.println("       0--退出");
           System.out.println("***************************************");
            System.out.println("请输入对应数字进行操作:");
        }

        public static void main(String[] args) {
            float[] score;
            int num;
            int choice;
            Score s = new Score();
            Scanner sc = new Scanner(System.in);
            //do-while循环展示操作菜单,完成循环操作
            do {
                s.menu();
                choice = sc.nextInt();
                try {
                    if(choice==0) {
                        System.out.println("退出程序!");
                        return;
                        //输入0时退出程序
                    }
                } catch (Exception e) {
                    System.out.println("输入有误,请重新输入!");
                    sc.next();
                    continue;
                    //输入格式错误时报错并进行下次循环
                }
                switch(choice){
                    case 1:
                        System.out.println("请输入要存入的成绩的数量:");
                        try {
                            num=sc.nextInt();
                            //数组长度小于1时循环输入
                            while(num<1) {
                                System.out.println("输入范围错误,请重新输入!");
                                num=sc.nextInt();
                            }
                        } catch (Exception e) {
                            System.out.println("输入错误,请重新输入!");
                            sc.next();
                            continue;
                        }
                        score=new float[num];
                        for(int i = 0 ; i<num ; i++) {
                            System.out.println("请输入第"+(i+1)+"个数据:");
                            try {
                                score[i]=sc.nextInt();
                                //成绩小于0或大于100时重新输入
                                if(score[i]<0 || score[i]>100) {
                                    System.out.println("输入范围错误,请重新输入!");
                                    i--;
                                }
                            } catch (Exception e) {
                                System.out.println("输入错误,请重试!");
                                continue;
                            }
                        }
                        System.out.println("初始化完成!");
                        s.setScore(score);
                        break;
                    case 2:
                        if(s.getScore()==null) {
                            System.out.println("请先初始化成绩单!");
                            continue;
                        }
                        System.out.println("前10个学生的有效成绩([0,100]内为有效成绩)的个数为:"+s.validScoreNum());
                        break;
                    case 3:
                        if(s.getScore()==null) {
                            System.out.println("请先初始化成绩单!");
                            continue;
                        }
                        System.out.println("前10个学生的总成绩为:"+s.sumScore());
                        break;
                    case 4:
                        if(s.getScore()==null) {
                            System.out.println("请先初始化成绩单!");
                            continue;
                        }
                        System.out.println("前10个学生的平均成绩为:"+s.averScore());
                        break;
                    default:
                        System.out.println("无效命令,请重新输入!");
                }
            }
            while(true);
        }
    }

  • 相关阅读:
    简单介绍动态链接过程
    MySQL:表所在库及注释信息查找
    [思考进阶]01 如何克服自己的无知?
    第四章 :Spring Boot 配置文件指南
    我的2022面试总结(已拿BAT头条网易滴滴亚马逊offer)
    LOJ#2833 「JOISC 2018 Day 1」帐篷 dp
    【LeetCode周赛】LeetCode第364场周赛
    网络七层协议在windows中是如何实现的
    【跟学C++】C++STL标准模板库——算法详细整理(下)(Study18)
    Agile Development
  • 原文地址:https://blog.csdn.net/weixin_51497502/article/details/125547072