实验二黑盒测试技术二DOC.docx
- 文档编号:11981448
- 上传时间:2023-04-16
- 格式:DOCX
- 页数:19
- 大小:40.13KB
实验二黑盒测试技术二DOC.docx
《实验二黑盒测试技术二DOC.docx》由会员分享,可在线阅读,更多相关《实验二黑盒测试技术二DOC.docx(19页珍藏版)》请在冰豆网上搜索。
实验二黑盒测试技术二DOC
实验二、黑盒测试技术
(二)
一、实验类型
实验类型为验证型,2个学时。
二、实验目的
(1)能熟练应用边界值和决策表测试技术进行测试用例设计;
(2)对测试用例进行优化设计;
三、背景知识
(一)边界值测试
1.边界值分析
边界值分析是考虑边界条件而选取测试用例的一种功能测试方法。
边界值分析关注输入空间的边界,以标识测试用例,因为错误更可能出现在输入变量的极值附近。
边界值分析的基本思想是:
使用在最小值、略高于最小值、正常值、略低于最大值和最大值处取输入变量值。
2.健壮性测试
健壮性是指在异常情况下,软件还能正常运行的能力。
健壮性考虑的主要部分是预期输出,而不是输入。
健壮性测试是边界值分析的一种简单扩展。
除了变量的5个边界分析取值还要考虑略超过最大值(max)和略小于最小值(min)时的情况。
3.最坏情况测试
最坏情况测试将意味着更大工作量,n变量函数的最坏情况测试会产生5的n次方个测试用例,而边界值分析只产生4n+1个测试用例。
(二)基于决策表的测试
决策表适合描述不同条件集合下采取行动的若干组合的情况。
使用决策表标识测试用例,则把条件解释为输入,行动解释为输出。
有时条件最终引用输入的等价类,行为引用被测试软件的主要功能处理部分,规则解释为测试用例。
对于有限条目决策表,如果有n个条件,则必须有2条规则。
如果不关心条目实际地表明条件是不相关的,则没有不关心条目的规则统计为1条规则,规则中每出现一个不关心条目,该规则数乘一次2。
四、实验设备
主流PC机一套,要求安装windows操作系统、VisualStudio2010或Eclipse开发工具和OFFICE工具
五、实验内容
NextDate函数
根据下面给出的规格说明,分别利用决策表方法,给出足够的测试用例并根据用例执行测试。
NextDate函数包含三个变量:
Month(月份)、day(日期)和year(年),函数的输出为输入日期后一天的日期。
例如,输入为2007年9月9日,则函数的输出为2007年9月10日。
要求输入变量month、day和year均为整数,并且满足下列条件:
(1)1<=month<=12;
(2)1<=day<=31;(3)1912<=year<=2050
C语言程序
JAVA程序界面
六、实验步骤
(1)首先根据题目要求编写nextday功能函数;
(2)根据功能性测试技术设计测试用例,主要考虑决策表测试技术:
分析条件桩和动作桩
输入:
-Month
-Day
-Year
为获得下一个日期,NextDate函数需执行的操作只有如下5种:
-day变量加1
-day变量复位为1
-month变量加1
-month变量复位为1
-year变量加1
考虑规则个数:
M1={月份:
每月有30天}
M2={月份:
每月有31天,12月除外}
M3={月份:
此月是12月}
M4={月份:
此月是2月}
D1={日期:
1≤日期≤27}
D2={日期:
日期=28}
D3={日期:
日期=29}
D4={日期:
日期=30}
D5={日期:
日期=31}
Y1={年:
年是闰年}
Y2={年:
年是平年}
制定初始决策表:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
.......
22
条件桩
Month在
M1
Day在
D1
Year在
--
动作桩
不可能
Day加1
√
Day复位
Month加1
Month复位
Year加1
化简决策表:
1
2
3
4
5
6
7
8
9
10
11
12
13
条件桩
Month在
Day在
Year在
动作桩
不可能
Day加1
Day复位
Month加1
Month复位
Year加1
(3)设计测试用例
用例ID
年份
月份
日期
期望输出
实际结果
1
2001
4
15
2001-04-16
2
3
4
5
6
7
8
9
10
11
12
13
七、实验报告要求
(1)完成初始决策表和化简决策表,并设计测试用例,记录实验结果;
(2)总结决策表设计测试用例的步骤
NextDay核心代码
packagecom.example.nextday;
importjava.awt.FlowLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JTextField;
publicclassNextDayextendsJFrameimplementsActionListener{
privateJTextFieldyear=null;
privateJTextFieldmonth=null;
privateJTextFieldday=null;
privateJTextFieldnextDate=null;
privateJButtoncomfir=null;
privateJButtonclear=null;
publicNextDay(){
add(newJLabel("年:
"));
year=newJTextField(3);
add(year);
add(newJLabel("月:
"));
month=newJTextField
(2);
add(month);
add(newJLabel("日:
"));
day=newJTextField
(2);
add(day);
add(newJLabel("NextDate:
"));
nextDate=newJTextField(10);
nextDate.setEditable(false);
add(nextDate);
comfir=newJButton("下一天");
clear=newJButton("清除");
add(comfir);
add(clear);
comfir.addActionListener(this);
clear.addActionListener(this);
setResizable(false);
setLayout(newFlowLayout());
setBounds(0,0,250,300);
setVisible(true);
}
/**
*判断是否为闰年
*@paramyear
*@return
*/
publicbooleanleap(intyear){
if((year%4==0&&year%100!
=0)||year%400==0){
returntrue;
}else{
returnfalse;
}
}
@Override
publicvoidactionPerformed(ActionEvente){
//TODOAuto-generatedmethodstub
if(e.getSource()==comfir){
inty=Integer.parseInt(year.getText().trim());
intm=Integer.parseInt(month.getText().trim());
intd=Integer.parseInt(day.getText().trim());
if((y>=1970&&y<=3000)&&(m>=1&&m<=12)&&(d>=1&&d<=31)){
//
if((m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12)){
//对12月的处理
if(m==12){
if(d<31){
nextDate.setText(y+"-"+m+"-"+(d+1));
}else{
nextDate.setText((y+1)+"-"+1+"-"+1);
}
//对1、3、5、7、8、10月份的处理
}else{
if(d<31){
nextDate.setText(y+"-"+m+"-"+(d+1));
}else{
nextDate.setText(y+"-"+(m+1)+"-"+1);
}
}
}else{
if(m==2){
if(leap(y)){
if(d<30){
if(d<29){
nextDate.setText(y+"-"+m+"-"+(d+1));
}else{
nextDate.setText(y+"-"+(m+1)+"-"+1);
}
}else{
JOptionPane.showMessageDialog(this,"输入日期有误",
"Erroe",JOptionPane.ERROR_MESSAGE);
year.setText("");
month.setText("");
day.setText("");
}
}else{
//平年的处理
if(d<29){
if(d<28){
nextDate.setText(y+"-"+m+"-"+(d+1));
}else{
nextDate.setText(y+"-"+(m+1)+"-"+1);
}
}else{
JOptionPane.showMessageDialog(this,"输入日期有误",
"Erroe",JOptionPane.ERROR_MESSAGE);
year.setText("");
month.setText("");
day.setText("");
}
}
}
}
}else{
//不满足输入条件
JOptionPane.showMessageDialog(this,"输入日期有误",
"Erroe",JOptionPane.ERROR_MESSAGE);
year.setText("");
month.setText("");
day.setText("");
}
}
if(e.getSource()==clear){
year.setText("");
month.setText("");
day.setText("");
}
}
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
newNextDay();
}
}
C++代码:
#include
#include
usingnamespacestd;
intmain()
{
stringntime;
inttmp;
while
(1)
{
cout<<"请输入日期,例如(0712-02-12)"< loop: cin>>ntime; while(ntime.length()! =10) { cout<<"您的输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[4]! ='-'||ntime[7]! ='-') { cout<<"您的输入格式有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[0]=='0'&&ntime[1]=='0'&&ntime[2]=='0'&&ntime[3]=='0') { cout<<"您的年份输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[5]>='2'||(ntime[5]=='1'&&ntime[6]>='3')) { cout<<"您的月份输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[5]=='0'&&ntime[6]=='0') { cout<<"您的月份输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while((ntime[8]=='3'&&ntime[9]>='2')) { cout<<"您的天数输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[8]=='0'&&ntime[9]=='0') { cout<<"您的天数输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while((((ntime[5]=='1'&&(ntime[6]=='0'||ntime[6]=='2'))||ntime[6]=='1'||ntime[6]=='3'||ntime[6]=='5'||ntime[6]=='7'||ntime[6]=='8')&&ntime[8]=='3'&&ntime[9]>='2')||(ntime[5]=='0'&&ntime[6]=='2'&&ntime[8]>='3')) { cout<<"您的天数输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(((ntime[5]=='1'&&ntime[6]=='1')||(ntime[5]=='0'&&(ntime[6]=='4'||ntime[6]=='6'||ntime[6]=='9')))&&(ntime[8]=='3'&&ntime[9]>='1')) { cout<<"您的天数输入有误,请重新输入日期,例如(0712-02-12)"< gotoloop; } while(ntime[0]=='9'&&ntime[2]=='9'&&ntime[3]=='9'&&ntime[1]=='9'&&ntime[5]=='1'&&ntime[6]=='2'&&ntime[8]=='3'&&ntime[9]=='1') { cout<<"您的输入超出范围,请重新输入日期,例如(0712-02-12)"< gotoloop; } for(inti=0;i { if((ntime[i]>='10'||ntime[i]<'0')&&ntime[i]! ='-') { cout<<"您的年份输入有误1,请重新输入日期,例如(0712-02-12)"< gotoloop; } } if(ntime[8]<'2'||(ntime[8]=='2'&&ntime[9]<='7')) { if(ntime[9]=='9') { ntime[9]='0'; ntime[8]=ntime[8]+1; } else { ntime[9]=ntime[9]+1; } cout<<"nextday为: "< } elseif(ntime[8]=='2'&&ntime[9]>='8') { if(ntime[5]=='0'&&ntime[6]=='2') { tmp=(ntime[0]-48)*1000+(ntime[1]-48)*100+(ntime[2]-48)*10+ntime[3]-48; if(tmp%400==0||(tmp%4==0&&tmp%100! =0)) { if(ntime[8]=='2'&&ntime[9]=='9') { ntime[6]=ntime[6]+1; ntime[8]='0'; ntime[9]='1'; } else { ntime[9]=ntime[9]+1; } cout<<"nextday为: "< } else { if(ntime[9]=='9') { cout<<"您的输入有误,这一年的2月没有29天"< cout<<"请输入日期,例如(0712-02-12)"< gotoloop; } else { ntime[6]=ntime[6]+1; ntime[8]='0'; ntime[9]='1'; cout<<"nextday为: "< } } } } elseif((ntime[5]=='1'&&ntime[6]=='1')||(ntime[5]=='0'&&(ntime[6]=='4'||ntime[6]=='6'||ntime[6]=='9'))) { ntime[9]=ntime[9]+1; if(ntime[8]=='3'&&ntime[9]=='1') { ntime[6]=ntime[6]+1; ntime[8]='0'; ntime[9]='1'; } cout<<"nextday为: "< } elseif((ntime[5]=='1'&&(ntime[6]=='0'||ntime[6]=='2'))||ntime[6]=='1'||ntime[6]=='3'||ntime[6]=='5'||ntime[6]=='7'||ntime[6]=='8') { ntime[9]=ntime[9]+1; if(ntime[9]>='2'&&ntime[8]=='3') { ntime[6]=ntime[6]+1; ntime[8]='0'; ntime[9]='1'; } if(ntime[5]=='1'&&ntime[6]>='3') { ntime[3]=ntime[3]+1; ntime[5]='0'; ntime[6]='1'; ntime[8]='0'; ntime[9]='1'; if(ntime[3]=='10') { ntime[3]='0'; ntime[2]=ntime[2]+1; } if(ntime[2]=='10') { ntime[2]='0'; ntime[1]=ntime[1]+1; } if(ntime[1]=='10') { ntime[1]='0'; ntime[0]=ntime[0]+1; } } cout<<"nextday为: "< } } return0; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 黑盒 测试 技术 DOC