软件测试NextDate函数决策表测试法实验报告.docx
《软件测试NextDate函数决策表测试法实验报告.docx》由会员分享,可在线阅读,更多相关《软件测试NextDate函数决策表测试法实验报告.docx(11页珍藏版)》请在冰豆网上搜索。
![软件测试NextDate函数决策表测试法实验报告.docx](https://file1.bdocx.com/fileroot1/2023-7/10/e4c2637e-03dd-4f76-a963-667af8984f8f/e4c2637e-03dd-4f76-a963-667af8984f8f1.gif)
软件测试NextDate函数决策表测试法实验报告
软件测试NextDate函数决策表测试法实验报告
一、实验目的:
掌握黑盒测试中的决策表测试法,并对被测程序设计测试用例。
二、实验环境
操作系统:
WindowsXP+SP2/win7
三、实验内容
1、编写一个NextDate函数。
2、掌握黑盒测试中的决策表测试法的基本步骤。
3、使用决策表法设计测试用例,对编写的函数实施测试,总结分析测试结果。
四、实验步骤
1、编写一个NextDate函数。
(C语言、C++)
2、根据黑盒测试的决策表测试法设计测试用例。
3、根据测试用例实施测试,并记录测试结果。
五、实验代码
#include
usingnamespacestd;
inta,b,c,y,m,d;
//判断是否为闰年
boolFeb(inty){
if((2060-y)%4==0)
return1;
else
return0;}
//年份的累加
intNextYear(inty){
a=y+1;
if(a>2060)
{cout<<"下一个日期已经超出了范围."<<"/n";
return1;}
else
returna;}
//月份的累加
intNextMonth(intm){
b=m+1;
if(b==13){
b=1;
NextYear(y);}
returnb;}
//天数的累加
intNextDay(intd){
c=d+1;
//大月满32天月份加1
if(c==32){
if(m==1|m==3|m==5|m==7|m==8|m==10|m==12)
{c=1;
NextMonth(m);}}
//小月满31天月份加1
if(c==31){
if(m==4|m==6|m==9|m==11)
{c=1;
NextMonth(m);}}
//若为闰年,2月满30天,月份加1
if(c==30){
if(Feb(y)&&m==2){
c=1;
b=3;}}
//若不是闰年,2月满29天,月份加1
if(c==29){
if(!
Feb(y)&&m==2){
c=1;
b=3;}}
returnc;}
//NextDate函数
intNextDate(inty,intm,intd){
if(y<1900|y>2060|m<1|m>12|d<1|d>31){
cout<<"输入不可能的日期,请输入正确的日期"<<"\n";
return1;}
if(m==4|m==6|m==9|m==11&&d==31){
cout<<"输入不可能的日期,请输入正确的日期"<<"\n";
return1;}
if(Feb(y)&&m==2&&d>29){
cout<<"输入不可能的日期,请输入正确的日期"<<"\n";
return1;}
if(!
Feb(y)&&m==2&&d>28)
{cout<<"输入不可能的日期,请输入正确的日期"<<"\n";
return1;}
else{
NextDay(d);
cout<<"Nextdateis"<return0;}}
//main函数
intmain()
{while
(1){
cout<<"请输入正确格式的日期."<<"\n";
cout<<"年份范围是1960-2060"<<"\n";
cout<<"年"<<"\n";
cin>>y;
cout<<"月"<<"\n";
cin>>m;
cout<<"日"<<"\n";
cin>>d;
a=y;
b=m;
c=d;
NextDate(y,m,d);}
return0;}
六、测试用例表
NxetDate函数求解给定某个日期的下一个日期的动作桩如下:
变量day加1操作;
变量day复位操作;
变量month加1操作;
变量month复位操作;
变量year加1操作
NxetDate函数的求解关键是日和月的问题,所以可以在下面的条件桩的基础上建立决策表
M1={month:
month有30天};
M2={month:
month有31天,12月除外};
M3={month:
month是12月};
M4={month:
month是2月};
D1={day:
1=D2={day:
day=28};
D3={day:
day=29};
D4={day:
day=30};
D5={day:
day=31};
Y1={year:
year是闰年};
Y2={year:
year不是闰年}
NxetDate函数决策表
选项
规则
1,2,3
4
5
6,7
8,9
10
11,12
13,14
15
16
17
18
19
20
21,22
条件
C1:
month在
M1
M1
M1
M2
M2
M3
M3
M3
M4
M4
M4
M4
M4
C2:
day在
D1,D2
D3
D4
D5
D1,D2
D3,D4
D5
D1,D2
D3,D4
D5
D1
D2
D2
D3
D3
D4
D5
C3:
year在
—
—
—
—
—
—
—
—
Y1
Y2
Y1
Y2
—
动作
A1:
不可能
√
√
√
A2:
day加1
√
√
√
√
√
A3:
day复位
√
√
√
√
√
A4:
month加1
√
√
√
√
A5:
month复位
√
A6:
year加1
√
NxetDate函数的测试用例组
测试用例
month
day
year
预期输出
TestCase1~3
9
16
2001
2001-9-17
TestCase4
9
30
2001
2001-10-01
TestCase5
9
31
2001
不可能的输入日期
TestCase6~9
1
16
2004
2004-1-17
TestCase10
1
31
2001
2001-2-01
TestCase11~14
12
16
2004
2004-12-16
TestCase15
12
31
2001
2002-1-01
TestCase16
16
2001
2001-1-17
TestCase17
2
28
2004
2004-2-29
TestCase18
2
28
2001
2001-3-01
TestCase19
2
29
2004
2004-3-1
TestCase20
2
29
2001
不可能的输入日期
TestCase21~22
2
30
2004
不可能的输入日期
七、测试用例执行结果
1、TestCase1~3
2、TestCase4
3、TestCase5
4、TestCase6~9
5、TestCase10
6、TestCase11~14
7、TestCase15
8、TestCase16
9、TestCase17
10、TestCase18
11、TestCase19
12、TestCase20
13、TestCase21~22
八、实验总结
1、通过本次实验,学会编写一个NextDate函数。
2、掌握了黑盒测试中的决策表测试法的基本步骤
3、实验过程中遇到了问题,通过查找资料和与同学讨论,得到了解决