您好,欢迎来到华佗健康网。
搜索
您的当前位置:首页实验二、黑盒测试技术(二)(DOC)

实验二、黑盒测试技术(二)(DOC)

来源:华佗健康网
实验二、黑盒测试技术(二)

一、 实验类型

实验类型为验证型,2个学时。

二、 实验目的

(1) 能熟练应用边界值和决策表测试技术进行测试用例设计; (2) 对测试用例进行优化设计;

三、 背景知识

(一)边界值测试

1. 边界值分析

边界值分析是考虑边界条件而选取测试用例的一种功能测试方法。边界值分析关注输入空间的边界,以标识测试用例,因为错误更可能出现在输入变量的极值附近。

边界值分析的基本思想是:使用在最小值、略高于最小值、正常值、略低于最大值和最大值处取输入变量值。

2.健壮性测试

健壮性是指在异常情况下,软件还能正常运行的能力。健壮性考虑的主要部分是预期输出,而不是输入。

健壮性测试是边界值分析的一种简单扩展。除了变量的5个边界分析取值还要考虑略超过最大值(max)和略小于最小值(min)时的情况。

3. 最坏情况测试

最坏情况测试将意味着更大工作量,n变量函数的最坏情况测试会产生5的n次方个测试用例,而边界值分析只产生4n+1个测试用例。 (二)基于决策表的测试

决策表适合描述不同条件集合下采取行动的若干组合的情况。使用决策表标识测试用例,则把条件解释为输入,行动解释为输出。有时条件最终引用输入的等价类,行为引用被测试软件的主要功能处理部分,规则解释为测试用例。

对于有限条目决策表,如果有n个条件,则必须有2条规则。如果不关心条目实际地表明条件是不相关的,则没有不关心条目的规则统计为1条规则,规则中每出现一个不关心条目,该规则数乘一次2。

四、 实验设备

主流PC机一套,要求安装windows操作系统、Visual Studio2010或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 Month在 M1 D1 -- √ 2 3 4 5 6 7 8 9 10 11 12 13 14 ....... 22 条件桩 Day在 Year在 不可能 Day加1 动作桩 Day复位 Month加1 Month复位 Year加1 化简决策表: 1 Month在 2 3 4 5 6 7 8 9 10 11 12 13 条件桩 Day在 Year在 不可能 Day加1 动作桩 Day复位 Month加1 Month复位 Year加1 (3) 设计测试用例 用例ID 1 2 3 4 5 6 7 年份 2001 月份 4 日期 15 期望输出 2001-04-16 实际结果 8 9 10 11 12 13

七、 实验报告要求

(1)完成初始决策表和化简决策表,并设计测试用例,记录实验结果; (2)总结决策表设计测试用例的步骤

NextDay核心代码 package com.example.nextday; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; public class NextDay extends JFrame implements ActionListener { private JTextField year = null; private JTextField month = null; private JTextField day = null; private JTextField nextDate = null; private JButton comfir = null; private JButton clear = null; public NextDay(){ add(new JLabel(\"年:\")); year = new JTextField(3); add(year); add(new JLabel(\"月:\")); month = new JTextField(2); add(month); add(new JLabel(\"日:\")); day = new JTextField(2); add(day); add(new JLabel(\"NextDate:\")); nextDate = new JTextField(10); nextDate.setEditable(false); add(nextDate); comfir = new JButton(\"下一天\"); clear = new JButton(\"清除\"); add(comfir); add(clear); comfir.addActionListener(this); clear.addActionListener(this); setResizable(false); setLayout(new FlowLayout()); setBounds(0, 0, 250, 300); setVisible(true); } /** * 判断是否为闰年 * @param year * @return */ public boolean leap(int year) { if ((year%4 == 0 && year%100 != 0) || year%400 == 0) { return true; }else { return false; } } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == comfir){ int y = Integer.parseInt(year.getText().trim()); int m = Integer.parseInt(month.getText().trim()); int d = 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\ 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\ year.setText(\"\"); month.setText(\"\"); day.setText(\"\"); } } } } } } }else { //不满足输入条件 JOptionPane.showMessageDialog(this, \"输入日期有误\ \"Erroe\ year.setText(\"\"); month.setText(\"\"); day.setText(\"\"); } } if(e.getSource()==clear){ year.setText(\"\"); month.setText(\"\"); day.setText(\"\"); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new NextDay(); } C++代码: #include #include using namespace std; int main() {

string ntime; int tmp; while(1) {

cout<< \"请输入日期,例如(0712-02-12)\" << endl; loop:

cin>>ntime;

while(ntime.length()!=10) {

cout<<\"您的输入有误,请重新输入日期,例如(0712-02-12)\"<while(ntime[4]!='-'||ntime[7]!='-') {

cout<<\"您的输入格式有误,请重新输入日期,例如(0712-02-12)\"<while(ntime[0]=='0'&&ntime[1]=='0'&&ntime[2]=='0'&&ntime[3]=='0') {

cout<<\"您的年份输入有误,请重新输入日期,例如(0712-02-12)\"<while(ntime[5]>='2'||(ntime[5]=='1'&&ntime[6]>='3')) {

cout<<\"您的月份输入有误,请重新输入日期,例如(0712-02-12)\"<while(ntime[5]=='0'&&ntime[6]=='0') {

cout<<\"您的月份输入有误,请重新输入日期,例如(0712-02-12)\"<while((ntime[8]=='3'&&ntime[9]>='2')) {

cout<<\"您的天数输入有误,请重新输入日期,例如(0712-02-12)\"<while(ntime[8]=='0'&&ntime[9]=='0') {

cout<<\"您的天数输入有误,请重新输入日期,例如(0712-02-12)\"<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)\"<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)\"<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)\"<for(int i=0; iif((ntime[i]>='10'||ntime[i]<'0')&&ntime[i]!='-') {

cout<<\"您的年份输入有误1,请重新输入日期,例如(0712-02-12)\"<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为:\"<else if(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为:\"<if(ntime[9]=='9') {

cout<<\"您的输入有误,这一年的2月没有29天\"<ntime[6]=ntime[6]+1; ntime[8]='0'; ntime[9]='1';

cout<<\"nextday为:\"<if((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为:\"<if((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为:\"<return 0; }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.com 版权所有 湘ICP备2023021991号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务