实验四(白盒测试) 下载本文

软件测试计划

测试目的

1. 2.

练习和掌握软件测试管理的一般过程与步骤;

掌握测试管理的人工过程和能够通过相关管理软件实现以下工作:

a) b) c) d) e)

配置软件资产信息、软件需求、软件模型和缺陷数据库; 创建和管理多个测试组和用户;

配置测试环境、编写详细测试计划、安排测试进度; 设计测试脚本、测试用例; 实施测试、执行测试和评估测试。

测试选题

对PriorDate程序(计算当前输入日期的前一天)的测试。

测试人员

何@@:软件测试计划及相关资料的编写与收集。

侯@@:对特定问题编写程序代码,并对其进行黑盒测试。 金@@:对特定问题编写程序代码,并对其进行白盒测试。

测试方法

使用白盒测试技术,测试内容包括语句覆盖测试、分支覆盖测试、条件覆盖测试、分支/条件覆盖测试、条件组合覆盖测试及基本路径测试。

测试资料

白盒测试

测试规划基于产品的内部结构进行测试,检查内部操作是否按规定执行,软件各个部分功能是否得到充分使用,则这种测试方法称为白盒测试(White-box Testing)方法。

白盒测试又称为结构测试、逻辑驱动测试或基于程序的测试,一般用来分析程序的内部结构。

白盒测试将被测程序看作一个打开的盒子,测试者能够看到被测源程序,可以分析被测程序的内部结构,此时测试的焦点集中在根据其内部结构设计测试用例。

",白盒测试要求是对某些程序的结构特性做到一定程度的覆盖,或者说这种测试是“基于覆盖率的测试”。 ",通常的程序结构覆盖有: 语句覆盖 判定覆盖

条件覆盖 判定/条件覆盖 路径覆盖

软件测试过程

单元测试:针对每个单元的测试, 以确保每个模块能正常工作为目标。

集成测试:对已测试过的模块进行组装,进行集成测试。目的在于检验与软件设计相关的程 序结构问题。

确认(有效性)测试:是检验所开发的软件能否满足所有功能和性能需求的最后手段。 系统测试:检验软件产品能否与系统的其他部分(比如,硬件、数据库及操作人员)协调 工作。

验收(用户)测试:检验软件产品质量的最后一道工序。主要突出用户的作用,同时软件开 发人员也应有一定程度的参与。

数据整理

测试所得到的用例测试报告、BUG报告,需要进行反馈和最后的归档,归档的工作按照项目计划中所规定的内容进行,反馈的工作在测试项结束后,整理成测试总结报告后进行,具体的日期,在项目计划中有规定。 不同阶段的测试,都需要重复以上的步骤。 其他必要的数据整理的工作,由项目经理在进行过程中进行安排。

PriorDate程序测试报告(白盒)

问题描述: 定义一个PriorDate函数,

PriorDate函数为了获得当前输入日期的前

一个日期, 执行如下操作:

如果输入日期day变量值大于1,则把day变量的值减1;

如果输入日期是2~12月份中某月的第一天,则把day变量的值置为前一个月的最后一 天,month变量的值减1;

如果输入日期是1月的第一天,则day变量的值置为31,month变量的值置为12,year 变量的值减1。

关于最后一天的判断:

??果是有31天的月份(1,3,5,7,8,10,12),day变量值为31; ??果是有30天的月份(4,6,9,11),day变量值为30; ??果是有29天的月份(闰年的2月),day变量值为29;

??果是有28天的月份(非闰年的2月),day变量值为28。

程序代码(开发环境:Windows7、VC++):

#include using namespace std; int main() {

int lastday,lastmonth,lastyear; int day,month,year; bool c1=1,c2=1,c3=1; while(c1&&c2&&c3) {

cout<<\

cout<<\例如2012年6月7号,输入形式为:2012 6 7\ cin>>year>>month>>day; c1=(day>=1)&&(day<=31);

c2=(month>=1)&&(month<=12); c3=(year>=1900)&&(year<=2050); if (!c1)

cout<<\ if (!c2)

cout<<\ if (!c3)

cout<<\ switch(month) {

case 5: case 7: case 10:

case 12:

if(day>1) {

lastday=day-1; lastmonth=month; lastyear=year; } else {

lastday=30;

lastmonth=month-1; lastyear=year; }

break; case 2: case 4: case 6: case 8: case 9: case 11:

if(day>1) {

lastday=day-1; lastmonth=month; lastyear=year; } else {

lastday=31;

lastmonth=month-1; lastyear=year; }

break; case 3:

if(day>1) {

lastday=day-1; lastmonth=month; lastyear=year; } else {

if(year%4==0&&year0!=0||year@0==0) {

lastday=29; lastmonth=2; lastyear=year; } else {

lastday=28; lastmonth=2; lastyear=year; } }

break; case 1:

if(day>1) {

lastday=day-1; lastmonth=month; lastyear=year; } else {

lastday=31; lastmonth=12; if(year!=1900)

lastyear=year-1;

else cout<<\ }

break; default:

cout<<\ }

if(c1&&c2&&c3)

cout<<\ \ \ }

return 0; }

测试方法:

白盒测试(语句覆盖、分支覆盖、条件覆盖、分支/条件覆盖、条件组合覆盖及基本路径测试方法)

测试用例设计:

程序的流程图如下图:

开始 O 天数1到31 B C 月份1到12 D No A No 打印输入天数出错 打印输入月份出错 年份1812到2012 2,4,6,8,9,11 F E No 打印输入年份出错 5,7,10,12 G default 语句 day>1 Yes 语句 L M No 语句 H Month匹配 3 1 K I day>1 Yes No N P 语句 语句 J day>1 Yes 语句 Q No 润年 U 语句 V 语句 R day>1 Yes S 语句 T year!=1812 Yes No W 语句 No Y c1&&c2&&c3 Y Z 结束 Yes Yes 打印 X 语句 1. 语句覆盖

语句覆盖就是设计若干个测试用例,运行被测程序,使得每一可执行语句至少执行一次。

? 测试用例的设计格式如下:

? 【输入的(a, b, x),输出的(a, b, x)】 测试数据 执行路径 预期结果 实际结果 month=13,day=32,year=2013 OACEGZ Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! the lastday is12 11 the lastday is12 11 2010 2010 the lastday is11 30 the lastday is11 30 2010 2010 the lastday is11 11 the lastday is11 11 2010 2010 the lastday is10 31 the lastday is10 31 2010 2010 the lastday is3 11 the lastday is3 11 2000 2000 the lastday is2 28 the lastday is2 28 2010 2010 the lastday is1 11 the lastday is1 11 2010 2010 the lastday is12 31 the lastday is12 31 2009 2009 lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460 month=12,day=12,year=2010 OBDFHLY month=12,day=1,year=2010 OBDFHMY month=11,day=12,year=2010 OBDFINY month=11,day=1,year=2010 OBDFIPY month=3,day=12,year=2000 OBDFJQY month=3,day=1,year=2010 OBDFJRY month=1,day=12,year=2010 OBDFKSY month=1,day=1,year=2010 month=1,day=1,year=1812 OBDFKTWY OBDFKTXY

2. 分支覆盖

执行足够的测试用例,使得程序中的每一个分支至少都通过一次 测试数据 month=13,day=32,year=2013 执行路径 OACEGZ 预期结果 实际结果 Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! month=12,day=12,year=2010 month=12,day=1,year=2010 month=11,day=12,year=2010 month=11,day=1,year=2010 month=3,day=12,year=2000 month=3,day=1,year=2000 month=3,day=1,year=2010 month=1,day=12,year=2010 month=1,day=1,year=2010 month=1,day=1,year=1812 OBDFHLY the lastday is12 11 the lastday is12 11

2010 2010 OBDFHMY the lastday is11 30 the lastday is11 30 2010 2010 OBDFINY the lastday is11 11 the lastday is11 11 2010 2010 OBDFIPY the lastday is10 31 the lastday is10 31 2010 2010 OBDFJQY the lastday is3 11 the lastday is3 11 2000 2000 OBDFJRY the lastday is2 29 the lastday is2 29 2000 2000 OBDFJRY the lastday is2 28 the lastday is2 28 2010 2010 OBDFKSY the lastday is1 11 the lastday is1 11 2010 2010 the lastday is12 31 the lastday is12 31

OBDFKTWY 2009 2009 OBDFKTXY lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460

3. 条件覆盖

执行足够的测试用例,使得判定中的每个条件获得各种可能的结果。 测试数据 month=13,day=32,year=2013 执行路径 OACEGZ 预期结果 实际结果 Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 month=0,day=0,year=1800 OACEGZ error! month=12,day=12,year=2010 month=12,day=1,year=2010 month=11,day=12,year=2010 month=11,day=1,year=2010 month=3,day=12,year=2000 month=3,day=1,year=2000 month=3,day=1,year=2010 month=1,day=12,year=2010 month=1,day=1,year=2010 month=1,day=1,year=1812 OBDFHLY OBDFHMY OBDFINY OBDFIPY OBDFJQY OBDFJRY OBDFJRY OBDFKSY error! the lastday is12 11 the lastday is12 11 2010 2010 the lastday is11 30 the lastday is11 30 2010 2010 the lastday is11 11 the lastday is11 11 2010 2010 the lastday is10 31 the lastday is10 31 2010 2010 the lastday is3 11 the lastday is3 11 2000 2000 the lastday is2 29 the lastday is2 29 2000 2000 the lastday is2 28 the lastday is2 28 2010 2010 the lastday is1 11 the lastday is1 11 2010 2010 OBDFKTWY the lastday is12 31 the lastday is12 31 2009 2009 OBDFKTXY lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460

4. 分支/条件覆盖

执行足够的测试用例,使得分支中每个条件取到各种可能的值,并使每个分支取到各种可能的结果。 测试数据 month=13,day=32,year=2013 执行路径 OACEGZ 预期结果 实际结果 Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! month=0,day=0,year=1800 OACEGZ month=12,day=12,year=2010 OBDFHLY the lastday is12 11 the lastday is12 11

2010 month=12,day=1,year=2010 month=11,day=12,year=2010 month=11,day=1,year=2010 month=3,day=12,year=2000 month=3,day=1,year=2004 month=3,day=1,year=2000 month=3,day=1,year=2010 month=1,day=12,year=2010 month=1,day=1,year=2010 month=1,day=1,year=1812 2010 OBDFHMY the lastday is11 30 the lastday is11 30

2010 2010 OBDFINY the lastday is11 11 the lastday is11 11 2010 2010 OBDFIPY the lastday is10 31 the lastday is10 31 2010 2010 OBDFJQY the lastday is3 11 the lastday is3 11 2000 2000 OBDFJRUY the lastday is2 29 the lastday is2 29 2004 2004 OBDFJRUY the lastday is2 29 the lastday is2 29 2000 2000 OBDFJRY the lastday is2 28 the lastday is2 28 2010 2010 OBDFKSY the lastday is1 11 the lastday is1 11 2010 2010 the lastday is12 31 the lastday is12 31

OBDFKTWY 2009 2009 OBDFKTXY lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460

5. 条件组合覆盖

执行足够的例子,使得每个判定中条件的各种可能组合都至少出现一次。 测试数据 month=13,day=32,year=2013 执行路径 OACEGZ 预期结果 实际结果 Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of month not in Value of month not in month=0,day=0,year=1800 OACEGZ month=0,day=1,year=1800 OBCEGZ the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! month=0,day=0,year=2000 OACFGZ Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 error! error! Value of month not in Value of month not in the range 1...12 the range 1...12 error! error! month=0,day=1,year=2000 OBCFGZ month=1,day=0,year=1800 OADFKTXZ Value of day not in the Value of day not in the range 1...31 range 1...31 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 OBDEKTXZ Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 OADFKTXZ Value of day not in the Value of day not in the range 1...31 range 1...31 OBDFKTXY the lastday is12 31 the lastday is12 31 1999 1999 OBDFHLY the lastday is12 11 the lastday is12 11 2010 2010 OBDFHMY the lastday is11 30 the lastday is11 30 2010 2010 OBDFINY the lastday is11 11 the lastday is11 11 2010 2010 OBDFIPY the lastday is10 31 the lastday is10 31 2010 2010 month=1,day=1,year=1800 month=1,day=0,year=2000 month=1,day=1,year=2000 month=12,day=12,year=2010 month=12,day=1,year=2010 month=11,day=12,year=2010 month=11,day=1,year=2010 month=3,day=12,year=2000 month=3,day=1,year=2004 month=3,day=1,year=2000 month=3,day=1,year=2008 month=3,day=1,year=2001 month=3,day=1,year=2010 OBDFJQY the lastday is3 11 the lastday is3 11 2000 2000 OBDFJRUY the lastday is2 29 the lastday is2 29 2004 2004 OBDFJRUY the lastday is2 29 the lastday is2 29 2000 2000 OBDFJRUY the lastday is2 29 the lastday is2 29 2008 2008 OBDFJRUY the lastday is2 28 the lastday is2 28 2001 2001 OBDFJRY the lastday is2 28 the lastday is2 28 2010 2010 month=1,day=12,year=2010 month=1,day=1,year=2010 month=1,day=1,year=1812 OBDFKSY the lastday is1 11 the lastday is1 11

2010 2010 the lastday is12 31 the lastday is12 31

OBDFKTWY 2009 2009 OBDFKTXY lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460

6. 基本路径测试方法

设计足够的测试用例,覆盖程序中所有可能的路径,其中控制流图如下图:

1 2 3 5 6 8 9 11 10 7 4 13 12 17 18 19 14 15 16 20 21 22 23 25 266 27 28 24 29 30 30 31 30

测试数据 month=13,day=32,year=2013 执行路径 OACEGZ 预期结果 实际结果 Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of month not in Value of month not in the range 1...12 the range 1...12 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 error! error! Value of day not in the Value of day not in the range 1...31 range 1...31 Value of month not in Value of month not in the range 1...12 the range 1...12 error! error! Value of month not in Value of month not in the range 1...12 the range 1...12 error! error! month=0,day=0,year=1800 OACEGZ month=0,day=1,year=1800 OBCEGZ month=0,day=0,year=2000 OACFGZ month=0,day=1,year=2000 OBCFGZ month=1,day=0,year=1800 OADFKTXZ Value of day not in the Value of day not in the range 1...31 range 1...31 Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 OBDEKTXZ Value of year not in Value of year not in the the range 1812...2012 range 1812...2012 OADFKTXZ Value of day not in the Value of day not in the range 1...31 range 1...31 OBDFKTXY the lastday is12 31 the lastday is12 31 1999 1999 OBDFHLY the lastday is12 11 the lastday is12 11 2010 2010 OBDFHMY the lastday is11 30 the lastday is11 30

month=1,day=1,year=1800 month=1,day=0,year=2000 month=1,day=1,year=2000 month=12,day=12,year=2010 month=12,day=1,year=2010 2010 month=11,day=12,year=2010 month=11,day=1,year=2010 month=3,day=12,year=2000 month=3,day=1,year=2004 month=3,day=1,year=2000 month=3,day=1,year=2008 month=3,day=1,year=2001 month=3,day=1,year=2010 month=1,day=12,year=2010 month=1,day=1,year=2010 month=1,day=1,year=1812 2010 OBDFINY the lastday is11 11 the lastday is11 11

2010 2010 OBDFIPY the lastday is10 31 the lastday is10 31 2010 2010 OBDFJQY the lastday is3 11 the lastday is3 11 2000 2000 OBDFJRUY the lastday is2 29 the lastday is2 29 2004 2004 OBDFJRUY the lastday is2 29 the lastday is2 29 2000 2000 OBDFJRUY the lastday is2 29 the lastday is2 29 2008 2008 OBDFJRUY the lastday is2 28 the lastday is2 28 2001 2001 OBDFJRY the lastday is2 28 the lastday is2 28 2010 2010 OBDFKSY the lastday is1 11 the lastday is1 11 2010 2010 the lastday is12 31 the lastday is12 31

OBDFKTWY 2009 2009 OBDFKTXY lastyear is not in range lastyear is not in range the lastday is12 31 the lastday is12 31

-858993460