实验3 黑盒测试:决策表法及测试用例设计
一、实验目的
1、掌握决策表的概念。
2、掌握决策表测试用例设计法。
二、实验任务
以下三个任务、至少完成一个
1、对NextDate问题运用决策表法设计测试用例,并执行测试,撰写实验报告。
NextDate (int month, int day, int year)函数规定:输入三个整数:month、day和year,函数的输出为输入日期后一天的日期。例如,输入为2006年3月7日,则函数的输出为2006年3月8日,year满足1920≤year≤2050。
实验步骤:
序号 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
|||
C1日 |
D1 |
Y |
Y |
||||||||||
D2 |
Y |
Y |
|||||||||||
D3 |
Y |
Y |
|||||||||||
D4 |
Y |
Y |
|||||||||||
D5 |
Y |
Y |
|||||||||||
C2月 |
M1 |
Y |
Y |
Y |
Y |
Y |
|||||||
M2 |
Y |
Y |
Y |
Y |
Y |
||||||||
M3 |
|||||||||||||
M4 |
|||||||||||||
C3年 |
Y1 |
||||||||||||
Y2 |
|||||||||||||
A1:没有该日期 |
√ |
||||||||||||
A2:日期加一 |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
||||||
A3:日期复位 |
√ |
√ |
|||||||||||
A4:月份增1 |
√ |
√ |
|||||||||||
A5:月份复位 |
|||||||||||||
A6:年増一 |
序号 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
||
C1日 |
D1 |
Y |
Y |
|||||||||||
D2 |
Y |
Y |
Y |
|||||||||||
D3 |
Y |
Y |
Y |
|||||||||||
D4 |
Y |
Y |
||||||||||||
D5 |
Y |
Y |
||||||||||||
C2月 |
M1 |
|||||||||||||
M2 |
||||||||||||||
M3 |
Y |
Y |
Y |
Y |
Y |
|||||||||
M4 |
Y |
Y |
Y |
Y |
Y |
Y |
Y |
|||||||
C3年 |
Y1 |
Y |
Y |
|||||||||||
Y2 |
Y |
Y |
||||||||||||
A1:没有该日期 |
√ |
√ |
√ |
|||||||||||
A2:日期加一 |
√ |
√ |
√ |
√ |
√ |
√ |
||||||||
A3:日期复位 |
√ |
√ |
√ |
|||||||||||
A4:月份增1 |
√ |
√ |
||||||||||||
A5:月份复位 |
√ |
|||||||||||||
A6:年増一 |
√ |
注:
M1={月份:30天/月},M2={月份:31天/月,12月除外},M3={月份:12月},M4{月份:2月}
D1{日期:1<=日<=27},D2{日期:日=28},D3{日期:日=29},D4{日期:日=30},D5{日期:日=31},
Y1={年:闰年},Y2={年:平年}
条件桩:
C1月份在{M1,M2,M3,M4}中之一,C2日期在{D1,D2,D3,D4}中之,C3年在{Y1,Y2}中之一
动作桩:
A1:没有该日期,A2:日期增1,A3:日期复位,A4:月份增1,A5:月份复位,A6:年增1
测试用例ID |
月 |
日 |
年 |
预期输出 |
1-3 |
4 |
12/28/29 |
2022 |
2022年4月13/29/30日 |
4 |
4 |
30 |
2022 |
2022年5月1日 |
5 |
4 |
31 |
2022 |
没有该日期(error) |
6-9 |
1 |
15/28/29/30 |
2022 |
2022年1月16/29/30/31日 |
10 |
1 |
31 |
2022 |
2022年2月1日 |
11-14 |
12 |
15/28/29/30 |
2022 |
2022年12月16/29/30/31日 |
15 |
12 |
31 |
2022 |
2002年1月1日 |
16 |
2 |
15 |
2022 |
2022年2月16日 |
17 |
2 |
28 |
2024 |
2024年2月29日 |
18 |
2 |
28 |
2022 |
2022年3月1日 |
19 |
2 |
29 |
2022 |
2022年3月1日 |
20 |
2 |
29 |
2022 |
没有该日期(error) |
21,22 |
2 |
30/31 |
2022 |
没有该日期(error) |
package com.shu.exer;
import java.util.Scanner;
public class NextDate {
public static void main(String[] args) {
// TODO Auto-generated method stub
int year;
int month;
int day;
Scanner in = new Scanner(System.in);
System.out.println("year:");
year = in.nextInt();
while(!(year>=1000&&year<=9999))
{
System.out.println("error");
return;
}
System.out.println("month:");
month = in.nextInt();
while(month>12||month<1)
{
System.out.println("error");
return;
}
System.out.println("day:");
day = in.nextInt();
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
while(day>31||day<1)
{
System.out.println("error");
return;
}
}
if(month==4||month==6||month==9||month==11)
{
while(day>30||day<1)
{
System.out.println("error");
return;
}
}
if((year%4==0&&year%100!=0)||(year%400==0))
{
if(month==2)
{
if(day>29)
{
System.out.println("error");
return;
}
else
{
if(day==29)
{
day=1;
}
else
{
day++;
}
}
}
}
else
{
if(month==2)
{
if(day>28)
{
System.out.println("error");
return;
}
else
{
if(day==28)
{
day=1;
}
else
{
day++;
}
}
}
}
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if(day==31)
{
month++;
day=1;
System.out.println(year+" "+month+" "+day);
break;
}
else
{
day++;
System.out.println(year+" "+month+" "+day);
break;
}
case 2:
if(day==1)
{
month++;
System.out.println(year+" "+month+" "+day);
break;
}
else
{
System.out.println(year+" "+month+" "+day);
break;
}
case 4:
case 6:
case 9:
case 11:
if(day==30)
{
month++;
day=1;
System.out.println(year+" "+month+" "+day);
break;
}
else
{
day++;
System.out.println(year+" "+month+" "+day);
break;
}
case 12:
if(day==31)
{
year++;
month=1;
day=1;
System.out.println(year+" "+month+" "+day);
break;
}
else
{
day++;
System.out.println(year+" "+month+" "+day);
break;
}
}
}
}
①测试情况部分截图:
②软件缺陷报告
模块名称 |
对NextDate问题进行软件测试 |
||
版本号 |
V1.0 |
测试人 |
XXX |
缺陷类型 |
代码实现 |
严重级别 |
5级 |
可重复性 |
是 |
缺陷状态 |
New |
测试平台 |
Win11 |
测试软件 |
Interlij IDEA |
简述 |
因用户输入产生的错误类别不明确,不知道因输入产生错误的原因 |
||
操作步骤 |
|
||
实际结果 |
Error |
||
预期结果 |
提示用户“2022年12月没有32日”,请重新输入 |
||
注释 |
无注释,建议适当增加注释,提高程序代码的可读性 |
2、假设一个中国的航空公司规定:
请用程序实现上述功能,并用决策表法设计测试用例,再执行测试,撰写实验报告。
实验步骤:同上
3、对三角问题运用决策表法设计测试用例,并执行测试,撰写实验报告。
实验步骤:同上