欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实验 1 黑盒测试

最编程 2024-04-21 17:52:34
...

一、实验目的

1、 掌握黑盒测试的基础知识;

2、 掌握黑盒测试的检查内容及测试目的;

3、 掌握黑盒测试的几种基本测试方法:等价类划分方法、边界值分析方法、因果图法和决策表法;

二、实验要求

1、  复习有关内容,理解黑盒测试;

2、  掌握等价类划分、边界值分析方法、因果图法和决策表法,并能设计出测试用例;

3、  对具体软件,能分别使用相应的黑盒测试方法设计测试用例,并实施测试、分析测试结果。

三、实验内容

 1、设计函数实现输入日期显示星期几,并用等价类及边界值法测试

实验步骤:

①  设计程序

②  划分等价类,得到等价类表。等价类表格式如下:

输入条件

有效等价类

唯一标识

无效等价类

唯一标识

1900到2050内的闰年

(1)

Year<1900

(10)

1900到2050内的平年

(2)

Year>2050

(11)

非数字

(12)

1,3,5,7,8,10,12

(3)

Month<1

(13)

4,6,9,11

(4)

Month>12

(14)

2

(5)

非数字

(15)

1~28

(6)

Day<1

(16)

29

(7)

Day>31

(17)

30

(8)

Year为闰年

且Month

为2时,Day>29

(18)

31

(9)

Year为平年

且Month

为2时,Day>28

(19)

Month=1,3,5,7,8,10,12时,Day>31

(20)

Month=4,6,9,11

时,Day>30

(21)

非数字

(22)

③  运用等价类划分法设计测试用例,得到测试用例表。测试用例表格式如下:

④ 运用边界值法设计测试用例。

2、找零钱最佳组合

   假设商店货品价格(R) 都不大于100元(且为整数),若顾客付款(P)100元内,现有一个程序能在每位顾客付款后给出找零钱的最佳组合(找给顾客货币张数最少)。假定此商店的货币面值只包括:50(N50)10(N10) 5(N5)1(N1) 四种。

   请结合等价类划分法和边界值分析法为上述程序设计出相应的测试用例。

实验步骤:

等价类表

测试用例

边界值测试

3、有一个饮料自动售货机(处理单价为5角钱)的控制处理软件,它的软件规格说明如下:

若投入5角钱的硬币,按下“橙汁”或“啤酒”的按钮,则相应的饮料就送出来。若投入1元钱的硬币,同样也是按“橙汁”或“啤酒”的按钮,则自动售货机在送出相应饮料的同时退回5角钱的硬币。

因果图法测试该程序,并撰写实验报告。

实验步骤:

①编写程序

②分析原因与结果

③画出因果图

④转化为决策表

⑤根据决策表设计测试用例,得到测试用例表

因果图

决策表

测试用例

4、航空服务查询问题:根据航线,仓位,飞行时间查询航空服务。

假设一个中国的航空公司规定:

   ① 中国去欧美的航线所有座位都有食物供应,每个座位都可以播放电影。

   ② 中国去非欧美的国外航线都有食物供应,只有商务仓可以播放电影。

   ③ 中国国内的航班的商务仓有食物供应,但是不可以播放电影

   ④ 中国国内航班的经济仓只有当飞行时间大于2小时时才有食物供应,但是不可以播放电影。

请用程序实现上述功能,并用决策表法设计测试用例,再执行测试,撰写实验报告。

实验步骤:

① 编写程序

② 构造决策表

③ 根据决策表设计测试用例,得到测试用例表

因果图

决策表

测试用例

四、实验思考

   ① 在实际的测试中,如何设计测试用例才能达到用最少的测试用例检测出最多的缺陷;

   ② 在进行用例设计时,如何考虑软件测试用例的充分性和减少软件测试用例的冗余性;

1.使用等价类不同的测试用例来进行测试,做到减少测试用例的冗余性;

2.进行边界测试查找程序缺陷;

3.根据过往经验及个人直觉推测出软件可能存在的缺陷,从而有针对性的设计测试用例。

五、代码
import java.util.Scanner;

public class Day {
    public static int which_week(int y, int m, int d){
        int w =  ((d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) % 7) +1;
        return w;
    }
    public static void main(String[] args) {
        int year,month,day;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年");
        try {
            year = scanner.nextInt();
        } catch (Exception e){
            System.out.println("输入日期无效");
            return;
        }
        System.out.println("请输入月");
        try {
            month = scanner.nextInt();
        } catch (Exception e){
            System.out.println("输入日期无效");
            return;
        }
        System.out.println("请输入日");
        try {
            day = scanner.nextInt();
        } catch (Exception e){
            System.out.println("输入日期无效");
            return;
        }
        if (year < 1900 || year > 2050){
            System.out.println("输入日期无效");
            return;
        }
        if (month < 1 || month > 12){
            System.out.println("输入日期无效");
            return;
        }
        if (day < 1 || day > 31){
            System.out.println("输入日期无效");
            return;
        }
        if (year % 4 == 0 && month == 2 && day > 29){
            System.out.println("输入日期无效");
            return;
        }
        if (year % 4 != 0 && month == 2 && day > 28){
            System.out.println("输入日期无效");
            return;
        }
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10){
            if (day >31){
                System.out.println("输入日期无效");
                return;
            }
        }
        if (month == 4 || month == 6 || month == 9 || month == 11){
            if (day > 30) {
                System.out.println("输入日期无效");
                return;
            }
        }
        int week = which_week(year,month,day);
        System.out.println("星期"+week);
    }
}
Day
import java.util.Scanner;

public class Back {
    public static void main(String[] args) {
        int N50 = 0,N10 = 0,N5 = 0,N1=0;
        double price,pay,value;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入商品价格");
        try {
            price = scanner.nextDouble();
        } catch (Exception e){
            System.out.println("输入价格无效");
            return;
        }
        System.out.println("请输入顾客支付金额");
        try {
            pay = scanner.nextDouble();
        } catch (Exception e){
            System.out.println("输入支付金额无效");
            return;
        }
        if (price > pay){
            System.out.println("无效,顾客付款小于商品价格");
            return;
        }
        if ( price>100 || pay > 100 || pay < 0 || price < 0){
            System.out.println("无效输入");
            return;
        }
        else {
            value = pay - price;
            if (value / 50 >= 1){
                N50 = (int) (value / 50);
                value = value - 50 * N50;
            }
            if (value / 10 >= 1){
                N10 = (int) (value / 10);
                value = value - 10 * N10;
            }
            if (value / 5 >= 1){
                N5 = (int) (value / 5);
                value = value - 5 * N5;
            }
            N1 = (int) (value);
        }
        System.out.println("1元" + N1 + "张");
        System.out.println("5元" + N5 + "张");
        System.out.println("10元" + N10 + "张");
        System.out.println("50元" + N50 + "张");
    }
}
Back
import java.util.Scanner;

public class Drinks {
    public static void main(String[] args) {
        int button1,button2;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请投币(一元请输入1,五角请输入2)");
        try {
            button1 = scanner.nextInt();
            if (button1 != 1 && button1 != 2){
                System.out.println("输入无效");
                return;
            }
        } catch (Exception e){
            System.out.println("输入无效");
            return;
        }
        System.out.println("请选择商品(啤机请输入1,橙汁请输入2)");
        try {
            button2 = scanner.nextInt();
            if (button2 != 1 && button2 != 2){
                System.out.println("输入无效");
                return;
            }
        } catch (Exception e){
            System.out.println("输入无效");
            return;
        }
        if (button1 == 2 && button2 == 1 ){
            System.out.println("请取走您的啤酒");
        }
        else if (button1 == 2 && button2 == 2 ){
            System.out.println("请取走您的橙汁");
        }
        else if (button1 == 1 && button2 == 1 ){
            System.out.println("请取走您的啤酒,将找零五角");
        }
        else if (button1 == 1 && button2 == 2 ){
            System.out.println("请取走您的橙汁,将找零五角");
        }


    }
}
Drinks
import java.util.Scanner;

public class Air {
    public static void query(int b1,int b2,int b3){
        if (b1 == 1){
            System.out.println("享受服务:食物供应、播放电影");
            return;
        }
        if (b1 == 2 && b2 == 1){
            System.out.println("享受服务:食物供应、播放电影");
            return;
        }
        if (b1 == 2 && b2 == 2){
            System.out.println("享受服务:食物供应");
            return;
        }
        if (b1 == 3 && b2 == 1){
            System.out.println("享受服务:食物供应");
            return;
        }
        if (b1 == 3 && b2 == 2 && b3 == 2){
            System.out.println("享受服务:食物供应");
            return;
        }
        else
            System.out.println("享受服务:无");
    }
    public static void main(String[] args) {
        int button1,button2,button3;
        System.out.println("欢迎使用航空服务查询系统");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您的航线(欧美请输入1,国外非欧美请输入2,国内请输入3)");
        try {
            button1 = scanner.nextInt();
            if (button1 != 1 && button1 != 2 && button1 !=3){
                System.out.println("输入无效");
                return;
            }
        } catch (Exception e){
            System.out.println("输入无效");
            return;
        }
        System.out.println("请输入您的舱位(商务舱请输入1,经济舱请输入2)");
        try {
            button2 = scanner.nextInt();
            if (button2 != 1 && button2 != 2){
                System.out.println("输入无效");
                return;
            }
        } catch (Exception e){
            System.out.println("输入无效");
            return;
        }
        System.out.println("请输入您的飞行时间(两小时以内请输入1,超过两小时请输入2)");
        try {
            button3 = scanner.nextInt();
            if (button3 != 1 && button3 != 2){
                System.out.println("输入无效");
                return;
            }
        } catch (Exception e){
            System.out.println("输入无效");
            return;
        }
        query(button1,button2,button3);
    }
}
Air

原文地址:https://www.cnblogs.com/Arisf/p/16034437.html

推荐阅读