Ch14-测试用例设计

上传人:xia****ai 文档编号:243155366 上传时间:2024-09-17 格式:PPT 页数:63 大小:804.50KB
返回 下载 相关 举报
Ch14-测试用例设计_第1页
第1页 / 共63页
Ch14-测试用例设计_第2页
第2页 / 共63页
Ch14-测试用例设计_第3页
第3页 / 共63页
点击查看更多>>
资源描述
,Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,软件测试方法和技术,- Ch.14,测试用例的设计,主讲教师:郭晓燕,第,14,章 软件测试用例的设计,14.1,测试用例概述,14.2,白盒测试用例设计方法,14.3,黑盒测试用例设计方法,14.4,测试用例的组织和跟踪,测试用例概述,如何以最少的人力、资源投入,在最短的时间内完成测试,发现软件系统的缺陷,保证软件的优良品质,则是软件公司探索和追求的目标。,测试用例是测试工作的指导,是软件测试的必须遵守的准则,更是软件测试质量稳定的根本保障。,什么是测试用例,测试用例可以独立进行测试执行的最小单元,测试内容的一系列情景和每个情景中必须依靠输入和输出,而对软件的正确性进行判断的测试文档,称为测试用例。,测试用例就是将软件测试的行为活动,做一个科学化的组织归纳。,软件测试是有组织性、步骤性和计划性的,为了能将软件测试的行为转换为可管理的、具体量化的模式,需要创建和维护测试用例,为什么需要测试用例,在开始实施测试之前设计好测试用例,避免盲目测试并提高测试效率,减少测试的不完全性;,测试用例的使用令软件测试的实施重点突出、目的明确;,根据测试用例的多少和执行难度,估算测试工作量,便于测试项目的时间和资源管理与跟踪;,减少回归测试的复杂程度,在软件版本更新后只需修正少量的测试用例便可展开测试工作,降低工作强度、缩短项目周期;,为什么需要测试用例,(,2,),功能模块的测试用例的通用化和复用化则会使软件测试易于开展,并随着测试用例的不断细化其效率也不断攀升;,根据测试用例的操作步骤和执行结果,为分析软件缺陷和程序模块质量提供依据;可以方便地书写软件测试缺陷报告;,可以根据测试用例的执行等级,实施不同级别的测试;,便于大型软件测试项目外包测试指导基础;,良好测试用例的特征,可以最大程度地找出软件隐藏的缺陷,可以最高效率的找出软件缺陷,可以最大程度地满足测试覆盖要求,既不过分复杂、也不能过分简单,使软件缺陷的表现可以清楚的判定,测试用例包含期望的正确的结果,待查的输出结果或文件必须尽量简单明了,不包含重复的测试用例,测试用例内容清晰、格式一致、分类组织,测试用例的组成元素与范例,测试用例编号,ID,测试用例标题,测试的模块,测试输入条件,期望的输出结果,其它说明,ID,类型,标题,测试步骤,期望的结果,说明,001,登录,输入正确密码,用户在登录界面输入正确的密码后,按回车键,程序提示登录成功,002,登录,输入错误密码,用户在登录界面输入错误的密码后,按回车键,程序提示输入密码错误,请重新输入,003,登录,不输入的空密码,用户在登录界面没有输入任何密码使密码为空后,按回车键,程序提示用户没有输入密码,请输入,程序应该告知用户没有输入密码,而不是密码错误,白盒测试用例设计方法,白盒测试用例的设计方法,逻辑覆盖:以程序的内部逻辑结构为基础,分为语句覆盖、判定覆盖、判定,-,条件覆盖、条件组合覆盖等,基本路径测试:在程序控制流程的基础上,分析控制构造的环路复杂性,导出基本可执行路径集合,从而设计测试用例。,白盒测试用例注意事项,由于测试路径可能非常多,由于时间和资源问题,选出足够多的路径测试,由于深入到程序编码,通常开发人员协助测试人员书写白盒测试用例,基本路径测试,Goal: exercise,each independent path,at least once.,Using the code, draw a corresponding,flow graph,(First drawing the activity diagram for the code may help, but is not required),Determine the,cyclomatic,complexity,of the flow graph.,Determine a,basis set,of linearly independent paths.,Prepare,test cases,that,force,the,execution of each path,in the basis set.,Example,Procedure: process records,1.,Do While,records remain,2.,Read,record;,3.,If,record field 1 = 0,Then,4.,store in buffer;,5.,increment counter;,6.,Else If,record field 2 = 0,Then,7.,reset counter;,8.,Else,store in file;,9.,End If,10.,End If,11.,End Do,End,Example (continued),1,9,10,11,2,4,5,7,8,3,6,V(G) = 4,基本路径测试,:,流程图,1,2,3,8,7,6,9,4,5,10,11,流程图复杂度确定,V(G) =number of regions (areas bounded by nodes and edgesarea outside the graph is also a region),V(G) = number of edges - the number of nodes + 2,V(G) = number of (simple) predicate nodes + 1,Cyclomatic,complexity:,a quantitative measure of the logical complexity of code,provides an upper bound on the number of paths that need to be tested in the code,V(G),modules,modules in this range are more error prone,Higher Cycloramic Complexity, more possibility in error,流程图复杂度例子,V(G)=4,1,2,3,7,8,6,9,4,5,10,11,Region 1,Region 2,Region 3,Region 4,确定线性独立的路径集合,Independent path, any path that introduces at least one new set of processing statements or a new condition,Basis set, set of,independent paths,through the code,Test cases,derived from a,basis set,are guaranteed to execute every statement at least one time during testing,Basis set is,not unique,Path1: 1-2-3-6-7-9-10-1-11,Basis path test example,Path2: 1-2-3-6-8-9-10-1-11,Path3: 1-2-3-4-5-10-1-11,Path4: 1-11,1,9,10,11,2,4,5,8,7,3,6,测试用例覆盖集合中每条路径,Basis path testing does not test all possible combinations of all paths through the code; it just tests every path at least once.,you do not need an activity diagram, but the picture will help when you trace component paths,count each logical testcompound tests count as the number of Boolean operators + 1 (i.e., count each simple predicate),basis path testing should be applied to all components, if possible, and to critical components,always,条件测试,Goal,: further exercises the,true,and,false,value of each simple,logical condition,in,a component.,Logical conditions,Simple condition,:(a rel-op b) where rel-op= (may be negated with NOT), e.g., ab; NOT(ab),Compound condition,: two or more simple conditions connected with AND, OR, e.g., (ab) AND (c(a+b+c),errors to test for include (incorrect/missing/extra):,Boolean operator relational operator,Boolean variable arithmetic expression,Boolean parenthesis,条件测试,(2),Domain testing,for an expression,E,1,rel-op,E,2, test for E,1, ,= ,E,2,guarantees detection of rel-op error if E,1,and E,2,are correct,to detect errors in E,1,/ E,2, the difference between E,1,and E,2,for the tests E,1,than E,2,should be as small as possible,for an expression with n variables, 2,n,tests are required,Branch testing,for a compound condition C, test true and false branches of C and every simple condition of C,e.g., for,C,= (,ab,) AND (,cb,TRUE, FALSE,cd,TRUE, FALSE,C,TRUE, FALSE,True AND True,T. And F., F. And T.,F. And F.,条件测试,- Example,But ( i = result = 0 ) :,maxint N,iN,result=maxint,-1 1,true false,1 0,false true,gives condition coveragefor all conditions,But it does not preservedecision coverage,always take care thatcondition coveragepreserves decision coverage :,decision / condition coverage,i:=i+1;,result:=result+i;,(,iN) and,(result=maxint),result=maxint,N 0,N := -N;,output(result);,output(,too large,);,exit,start,yes,no,no,yes,yes,no,分支测试,Branch Coverage,Execute the enough test cases,,,attempting to cover all the paths in the software:,- Get both “True” and “False”,- Go through each branch,。,For example,IF b THEN s1 ELSE s2,CASE x OF1 : .2 : .3 : .,分支测试,-,example,1,PROGRAM,som,(,maxint, N : INT ),2,INT result := 0 ; i := 0 ;,3,IF,N 0,4,THEN,N := - N ;,5,WHILE,( i N ),AND,( result =,maxint,),6,DO,i := i + 1 ;,7,result := result + i ;,8,OD,;,9,IF,result =,maxint,10,THEN,OUTPUT ( result ),11,ELSE,OUTPUT ( “too large” ),12,END,.,分支测试,-,continued,i:=i+1;,result:=result+i;,(,iN) and,(result=maxint),result=maxint,N 0,N := -N;,output(result);,output(,too large,);,exit,start,yes,no,no,yes,yes,no,N =0),result=0 i=0,Goal,: execute loops at their boundaries and within their bounds.,循环测试,1,1.,Simple Loops (n iterations),skip the loop entirely,only one pass through the loop,two passes through the loop,m passes through the loop where m n,n-1, n, n+1 passes through the loop,循环测试,2,2.,Nested Loops,BeizerBEI90,Conduct simple loop tests for the,innermost,loop while holding the outer loops at their,minimum iteration,Work,outward, conducting tests for the nextinnermost loop,Continue until all the loops have been tested,tests grow geometrically as the level of nesting increases,循环测试,3,Unstructured Loops,redesign!,3.,Concatenated Loops,independent loops,simple loop testing,dependent loops,nested loop testing,等价类测试用例设计方法,黑,盒测试用例的设计方法之一,等价类划分,:,在分析需求规格说明的基础上划分等价类,列出等价类表。,将程序可能的输入数据分成若干个子集,从每个子集选取一个代表性的数据作为测试用例,,等价类是某个输入域的子集,在该子集中每个输入数据的作用是等效的。,等价类的分类:有效等价类和无效等价类。有效等价类是有意义的、合理的输入数据,可以检查程序是否实现了规格说明中所规定的功能和性能。无效等价类与有效等价类的意义相反。,设计测试用例时,要同时考虑这两种等价类。因为软件不仅要能接收合理的数据,也要能经受意外的考验。经过正反的测试才能确保软件具有更高的可靠性。,all inputs,i,1,i,4,i,2,i,3,确定等价类的方法,在输入条件规定了取值范围或值的个数的情况下,则可以确立一个有效等价类和两个无效等价类。,in range,greater than range,less than range,value,greater than value,less than value,在输入条件规定了输入值的集合或者规定了“必须如何”的条件的情况下,可以确立一个有效等价类和一个无效等价类。,在输入条件是一个布尔量的情况下,可确定一个有效等价类和一个无效等价类,确定等价类的方法(,2,),not member of set,member of set,Boolean,Non-Boolean,确定等价类的方式,(3),在规定了输入数据的一组值,(,假定,n,个,),,并且程序要对每一个输入值分别处理的情况下,可确立,n,个有效等价类和一个无效等价类。,在规定了输入数据必须遵守的规则的情况下,可确立一个有效等价类,(,符合规则,),和若干个无效等价类,(,从不同角度违反规则,),。,个人月收入,-,x,税率,x,=1600 0%,1600,x,2100 5%,500 =,x, 3600 10%,3600 =,x, 6600 15%,6600 =,x, 21600 20%,21600 =,x,101600 45%,等价类测试用例,-Example,等价类,1: Integer,等价类,2: Decimal fraction,等价类,3: Negative,等价类,4: Invalid input,根据等价类创建测试用例的步骤,建立等价类表,列出所有划分出的等价类:,输入条件,有效等价类,无效等价类,为每个等价类规定一个唯一的编号;,设计一个新的测试用例,使其尽可能多地覆盖尚未覆盖的有效等价类。重复这一步,最后使得所有有效等价类均被测试用例所覆盖;,设计一个新的测试用例,使其只覆盖一个无效等价类。重复这一步使所有无效等价类均被覆盖。,边界值测试用例设计方法,程序的很多错误发生在输入或输出范围的边界上,因此针对各种边界情况设置测试用例,可以发现不少程序缺陷。,设计方法:,确定边界情况(输入或输出等价类的边界),选取正好等于、刚刚大于或刚刚小于边界值作为测试数据,确定边界值的方法,如果输入条件规定了值的范围,则应取刚达到这个范围的边界的值,以及刚刚超越这个范围边界的值作为测试输入数据。,如果输入条件规定了值的个数,则用最大个数、最小个数、比最小个数少一、比最大个数多一的数作为测试数据。,a,b,a,b,确定边界值的方法(,2,),如果程序的规格说明给出的输入域或输出域是有序集合,则应选取集合的第一个元素和最后一个元素作为测试用例。,如果程序中使用了一个内部数据结构,则应当选择这个内部数据结构的边界上的值作为测试用例。,Test cases for,ABS(x,) :,class x = 0, arbitrary value x = 100,classes x = 0, on boundary :x = 0,classes x = 0, below and above:x = -1, x = 1,Test cases :,Class arbitrary value: X1 = 123123,Class boundary value: X2 = 12345,Class boundary value: X3 = 1234567,Class boundary value: X4 = 1,Class boundary value: X5 = 0,Class invalid value: X6 = -123123,Class invalid value: X7 =,asdasd,Others?,BVA Example 2,Test a function which limit user input to 6-digit positive integer,Class invalid value: X8 = 000123,X9 = asd123,X10 = Empty,BVA Example 3,Test cases :,Class arbitrary value: Random select some options Class boundary value: Select all options Class boundary value: Select none option Class boundary value: Select 1 option,二进制,Term,Range or Value,Bit,Nibble,Byte,Word,Kilo,Mega,Giga,Tera,0 or 1,0-15 ,0-255,0-65535 or 0-4294967295,1024,1048576,1073741824,1099511627776,Binary: 0 and 1, byte is made up of 8 bits, word is made up of 4 bytes, ,ASCII Table,Character,ASCII Value,Character,ASCII Value,Null,Space,/,0,1,2,9,;,A,0,32,47,48,49,50,57,58,64,65,B,Y,Z,a,b,y,z,66,89,90,91,96,97,98,121,122,123,字符编辑域,Default,Empty,Blank,Null,Zero,None,一些特殊的边界值,Numeric,Character,Position,Quantity,Speed,Location,Size,First/last,,,First-1/Last+1,Min/Max,,,Min-1/max+1,Star/Finish,,,Start-1/Finish+1,Empty/Full,Less than empty/ more than full,Slower/Faster,Largest/Smallest,Over/Under,,,just Over/Just Under,Shortest/Longest, ,错误推测法测试用例设计,基于经验和直觉推测程序中所有可能存在的各种错误,从而有针对性地设计测试用例。,发现程序经常出现的错误的方法:,单元测试中发现的模块错误;,产品的以前版本曾经发现的错误;,输入数据为,0,或字符为空;,当软件要求输入时,(,比如在文本框中,),不是没有输入正确的信息,而是根本没有输入任何内容,单单按了,Enter,键;,这种情况在产品说明书中常常忽视,程序员也可能经常遗忘,但是在实际使用中却时有发生。程序员总会习惯性的认为用户要么输入信息,不管是看起来合法的或非法的信息,要不就会选择,Cancel,键放弃输入,,测试场景法设计测试用例,现在的软件几乎都是用事件触发来控制流程的,事件触发时的情景便形成了场景,而同一事件不同的触发顺序和处理结果就形成事件流。这种在软件设计方面的思想也可引入到软件测试中,可以比较生动地描绘出事件触发时的情景,有利于测试设计者设计测试用例,同时使测试用例更容易理解和执行。,因果图法测试用例设计,多种输入条件的组合,产生多种结果设计测试用例。,设计方法:,分析软件规格说明文档描述的哪些是原因(输入条件),哪些是结果(输出条件),给每个原因和结果赋予一个标示符。,找出原因与结果,原因与原因之间的对应关系,划出因果图,在因果图上标上哪些不可能发生的因果关系,表明约束或限制条件,根据因果图,创建判定表,将复杂的逻辑关系和多种条件组合很具体明确的表示出来,把判定表的每一行作为依据设计测试用例。,因果图法,Sample 1,Valid equivalence classes :,conditionvalid eq. classes .abs(N) N, 0,N,0maxint, k ,maxint, k ,maxint,Test Cases :,maxintNresult maxintNresult,55105510000 5410error100-11 56105510011 000,Given inputs,maxint,and N compute result,:,K=0,|,N,|,k,result = if this 0,,,B0,,,C0,,且,A+BC,,,B+CA,,,A+CB,;,如果是等腰的,还要判断,A=B,,或,B=C,,或,A=C,;,如果是等边的,则需判断是否,A=B,,且,B=C,,且,A=C,。,案例研究,1,:判断三角形的形状(续,1,),创建等价类表:,输入条件,有效等价类,无效等价类,是否三角形的,三,条边,(,A0,),,(,1,),(,B0,),,(,2,),(,C0,),,(,3,),(,A+BC,),,(,4,),(,B+CA,),,(,5,),(,A+CB,),,(,6,),(,A0,),,(,7,),(,B0,),,(,8,),(,C0,),,(,9,),(,A+BC,),,(,10,),(,B+CA,),,(,11,),(,A+CB,),,(,12,),是否等腰三角形,(,A=B,),,(,13,),(,B=C,),,(,14,),(,C=A,),,,(,15,),(,AB,),and,(,BC,),and,(,CA,),(,16,),是否等边三角形,(,A=B,),and,(,B=C,),and,(,C=A,),(,17,),(,AB,),,(,18,),(,BC,),,(,19,),(,CA,),,(,20,),案例研究,1,:判断三角形的形状(续,2,),确定等价类输入数据:,序号,【A,,,B,,,C】,覆盖等价类,输出,1,【3,,,4,,,5】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),一般三角形,2,【0,,,1,,,2】,(,7,),不能构成三角形,3,【1,,,0,,,2】,(,8,),4,【1,,,2,,,0】,(,9,),5,【1,,,2,,,3】,(,10,),6,【1,,,3,,,2】,(,11,),7,【3,,,1,,,2】,(,12,),8,【3,,,3,,,4】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,13,),等腰三角形,9,【3,,,4,,,4】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,14,),10,【3,,,4,,,3】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,15,),11,【3,,,4,,,5】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,16,),非等腰三角形,12,【3,,,3,,,3】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,17,),是等边三角形,13,【3,,,4,,,4】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,14,),(,18,),非等边三角形,14,【3,,,4,,,3】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,15,),(,19,),15,【3,,,3,,,4】,(,1,),(,2,),(,3,),(,4,),(,5,),(,6,),(,13,),(,20,),案例研究,2,:测试用户登录对话框的功能,测试场景:,在各种输入条件下,测试程序的登录对话框功能,。,用户名和密码的规则如下:,用户名长度为,6,至,10,位(含,6,位和,10,位),用户名由字符(,a-z,、,A-Z,),和数字(,0-9,)组成,不能为空、空格和特殊字符,密码规则同用户名规则,案例研究,2,:登录对话框的功能(续,1,),确定输入数据的情形:,操作步骤,预期结果,输入正确的用户名和口令(均为,6,位),点击,OK,按钮,进入系统,输入正确的用户名和口令(均为,10,位) ,点击,OK,按钮,进入系统,输入正确的用户名和口令(均为,6,至,8,位之间),,进入系统,用户名为空,,提示输入用户名不能进入系统,用户名为空格,,提示无效用户名不能进入系统,用户名小于,6,位,,提示用户名太短不能进入系统,案例研究,2,:登录对话框的功能(续,2,),确定具体的输入数据:,“用户名”,“口令”,“预期结果”,说明,“,user10”,“,pass10”,进入系统,正确的用户名和口令,(6,位,),“,user789”,“,pass789”,进入系统,正确的用户名和口令,(7-9,位,),“,user000010”,“,pass000010”,进入系统,正确的用户名和口令,(10,位,),“”,“,pass”,提示输入用户名,不能进入系统,用户名为空,“空格”,“,pass”,提示无效用户名,不能进入系统,用户名为空格,“,user”,“,userpass,”,提示用户名太短,不能进入系统,用户名小于,6,位,“,user0000011”,“,userpass,”,提示用户名太长,不能进入系统,用户名大于,10,位,案例研究,3,:压力,/,负载测试用例设计,设计目的,:,验证程序在承受某种负载或压力下是否能够正常运行,找出程序安全运行的临界值,适用情形,:,服务器,/,客户机局域网,服务器,/,浏览器互联网,设计方法,:,设计出不同等级的压力条件,压力,/,负载分类与代号,:,CPU,速度,CS,CPU,使用量,CU,磁盘空间,DS,物理内存,PM,虚拟内存使用量,VM,登录用户的数量,UN,传输带宽,BW,传输数据的大小,DN,案例研究,3,:,压力,/,负载测试用例设计,(续1),编号,CS,CU,DS,PM,VM,UN,BW,DN,应该产生的行为,结果,说明,01,PIII 800,10%,50,MB,64,MB,50%,30,1,M,5,M,正常,02,PIV1800,80%,100,MB,128,MB,30%,100,0.5,M,10,M,无法响应,03,PII 500,25%,600,MB,256,MB,15%,10,2.5,M,20,M,正常,04,PIV2800,35%,400,MB,512,MB,80%,500,0.5,M,50,M,无法响应,05,PIV3200,50%,200,MB,1024,MB,65%,2000,1.5,M,100,M,无法响应,案例研究,4,:,测试软件对话框的界面设计,Deployment,Testcase,Test Case ID,:,62,Title,:,UserExitForm,Path,:,DeploymentGeneral,Author,:,xxxxx,Purpose,: make sure the dialog to test is properly designed, look for truncations, wrong tab orders, duplicated hotkeys,overlappings,and any other,pos,s,ible,issues,Steps,:,Pre-steps,:,1. Launch App.,2. Go to “Tools” / “Import/Export Settings”,3. Select “General development settings”,4. Click Reset Settings,5. If you are prompted to save your settings, click “Dont save”,6. A dialog appears telling you that the operation had been successful,案例研究,5,:,测试中断安装软件的功能,Purpose:,Verify the app can be canceled during installation,Test Steps,:,1. Launch App Name,2. From the drop down menu select File, New and Project,3. The New project Dialog box should appear,4. In “Project Types”, select “Other Project Types” and under this, “Setup and deployment”. From the “Templates” select a setup project, give the project a name for example Deploy1 and press “OK”,5. From the “Build” menu click “Build Solution” and wait until the project has been built,6. Close the project and navigate to the folder where you saved your project,7. Double click the Setup folder and then double click the Debug folder,8. Click the Setup.exe to launch the Windows Installer,9. At the first stage of the wizard click the “Cancel” button and click “Yes” when asked are you sure you want to exit,10. The Installation Interrupted dialog appears,案例研究,6,:,测试软件中文字符集的支持,Create and structure a site with GB 18030 character,App name is a very complex product, and its ability of site management as well as multimedia authoring is quite powerful. The following,testcases,is used to test the performance in supporting GB 18030 when creating a site.,Title: Create a Blank Site with GB 18030 Character,Steps,:,Launch App name.,Choose File New Site to open the site wizard.,Select Single User and click Next.,Select Blank Site to create a project folder and Click Next.,In Site Name field on the dialog, type in or copy/paste GB 18030 characters as site name. Click Next.,Choose location where you want to store all folders of this new site.,Verify this new site is created, with correct project folder name as desired.,In File panel, verify this site name with GB18030 character can display properly as desired.,Q & A,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 小学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!