软件工程英文教学课件:Ch18 Testing Conventional Applications_第1页
软件工程英文教学课件:Ch18 Testing Conventional Applications_第2页
软件工程英文教学课件:Ch18 Testing Conventional Applications_第3页
软件工程英文教学课件:Ch18 Testing Conventional Applications_第4页
软件工程英文教学课件:Ch18 Testing Conventional Applications_第5页
已阅读5页,还剩42页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1Chapter 18Testing Conventional ApplicationsSoftware Engineering: A Practitioners Approach, 7/e by Roger S. Pressman2TestabilityOperabilityit operates cleanlyObservabilitythe results of each test case are readily observedControllabilitythe degree to which testing can be automated and optimizedDecomp

2、osabilitytesting can be targetedSimplicityreduce complex architecture and logic to simplify testsStabilityfew changes are requested during testingUnderstandabilityof the design3What is a “Good” Test?A good test has a high probability of finding an errorA good test is not redundant.A good test should

3、 be “best of breed”(所设计的测试用例同类最优) A good test should be neither too simple nor too complex4Internal and External ViewsAny engineered product can be tested in one of two ways: Knowing the specified function that a product has been designed to perform, tests can be conducted that demonstrate each func

4、tion is fully operational while at the same time searching for errors in each function. (black-box method)Knowing the internal workings of a product, tests can be conducted to ensure that “all gears mesh(所有齿轮都相互啮合)“, that is, internal operations are performed according to specifications and all inte

5、rnal components have been adequately exercised. (white-box method)5Test Case DesignOBJECTIVECRITERIACONSTRAINTto uncover errorsin a complete mannerwith a minimum of effort and time6Exhaustive Testing(穷举法)There are 1014 possible paths! If we execute one test per millisecond, it would take 3170 years

6、to test this program!loop 20 X7Selective Testing(选择法)loop 20 XSelected path8Software TestingMethodsStrategieswhite-boxmethods black-box methods9White-Box Testing. our goal is to ensure that all statements and conditions have been executed at least once .Basis Path Testing (路径覆盖测试)Logical Condition T

7、esting (逻辑覆盖测试)10Basis Path Testing (路径覆盖测试)Step1:Draw the flow graph based on the design or the code of program(绘制程序图).Step 2: Compute the cyclomatic complexity V(G) of the flow graph(计算程序图的环域复杂度V(G).Step 3: Determine the basis sets of the independent paths (选择能够覆盖所有边的V(G)条独立路径).Step 4: Design test

8、 cases that will force execution of each independent path in the basis sets(设计强制执行每条路径的测试用例集). 2022/7/1811程序图(flow graph):一种简化的流程图,用来考察测试路径的工具。(1) 程序图的基本控制结构: 结点:代表一条或多条顺序执行的语句,程序流程图中的处理方框和菱形判定框可映射为结点。边:代表控制流,类似于程序流程图中的箭头,(一条边必须终止于一个结点,即使该结点并不代表任何语句)封闭区域:由边和结点圈起来的范围。Basis Path Testing- flow graph202

9、2/7/1812(2)程序图的结构简化:程序图可将顺序执行的多个结点合并为1个结点;对流程图中含有复合条件的判定框,先分解为几个简单条件判定框,再画程序图。程序图关注的重点是判断框,而不是执行细节。(3)程序图的用途:安排与验证程序的路径测试;考察与改进程序的结构复杂性。 Basis Path Testing - flow graph2022/7/1813例:画出下面用PDL描述的程序段的程序图IF a OR b THEN procedure x ELSE procedure yENDIFqBasis Path Testing - flow graph2022/7/1814分解复合判断后的程序

10、图如下:复合条件被分解为2个单独的结点a和b。R1和R2是程序图的2个封闭区域。qBasis Path Testing- flow graph15Basis Path Testing - cyclomatic complexity we compute the cyclomatic Complexity:1) number of simple decisions + 1 or2) number of enclosed areas + 1In this case, V(G) = 416Basis Path Testing- independent pathsWe derive the indep

11、endent paths:Since V(G) = 4,there are four paths:Path 1: 1,2,3,6,7,8Path 2: 1,2,3,5,7,8Path 3: 1,2,4,7,8Path 4: 1,2,4,7,2,4,.7,8Finally, we derive testcases to exercise these paths.1234567817Basis Path Testing Notesyou dont need a flow chart, but the picture will help when you trace program pathsbas

12、is path testing should be applied to critical modules2022/7/1818实例:冒泡排序程序,要求:画出程序流程图;将程序流程图转换为程序图;计算环域复杂度;采用路径测试法进行白盒测试,请设计测试用例,使其满足路径覆盖。sort(int a ,int n) int i,j,temp; for (i=0;in;i+) for (j=0;jaj+1) temp=aj; aj=aj+1; aj+1=temp; 入口返回injaj+1Yi=i+1j=j+1Y2022/7/1819解:程序流程图程序图环域复杂度V(G)=判定结点数+1 =3+1 =4

13、V(G)=封闭区域+1 =3+1 =4入口返回injaj+1Yi=i+1j=j+1Y2022/7/1820解(续)设计测试用例集使其满足路径覆盖(即:点覆盖+边覆盖) 1)A1=4,6,n=2 2)A2=6,4,2,n=3说明:测试集需覆盖4条路径P1:1,2,3,0P2:1,2,3,4,5,9,3,0P3:1,2,3,4,5,6,8,5,9,3,0P4:1,2,3,4,5,6,7,8,5,9,3,0A1覆盖了P1,P2,P4A2覆盖了P1,P2,P3入口返回injaj+1Yi=i+1j=j+1Y123465780921Logical Condition Testing(逻辑覆盖测试)The

14、test case design method that exercises the logical conditions contained in a program module 逻辑覆盖测试的5种标准(由弱到强)(1) 语句覆盖:每条语句至少执行1次;(2) 判定覆盖:每一判定的每一分支至少执行1次;(3) 条件覆盖:每一判定中的每个条件,分别按“真”和“假”至少各执行1次;(4) 判定/条件覆盖:同时满足判定覆盖和条件覆盖的要求;(5) 条件组合覆盖:求出判定中所有条件的各种可能的组合值,每一可能的条件组合至少执行1次。2022/7/1822利用流程图中的判定框设计测试用例。PROCE

15、DURE EXAMPLE(A,B:REAL;VAR X:REAL) BEGIN IF (A1)AND(B=0) THEN X:=X/A; IF (A=2)OR(X1) THEN X:=X+1 END语句覆盖测试数据如表所示,满足语句覆盖准测。入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNNABX期望204红线逻辑覆盖测试举例2022/7/1823 判定覆盖期望结果应该有具体的值,这里用有颜色的线表示。测试数据如下表所示,满足判定覆盖准测。语句覆盖判定覆盖称完全覆盖(路径覆盖)。ABX期望204红线111蓝线入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YY

16、NN判定1判定2判定2判定1FTFT逻辑覆盖测试举例2022/7/1824 条件覆盖使每个条件都能取值为真和假。测试数据如右下表所示,满足条件覆盖准测。 ABX期望214红线101蓝线判定2判定1A1B=0A=2X1FFTFTFTT入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN判定1判定2逻辑覆盖测试举例2022/7/1825 判定/条件覆盖期望结果应该有具体的值,这里用有颜色的线表示。测试数据如右下表所示,满足判定/条件覆盖准测。 判定2判定1FTFTA1B=0A=2X1FFTFTFTT入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN判定1判定2

17、ABX期望204红线111蓝线逻辑覆盖测试举例2022/7/1826条件组合覆盖期望结果应该有具体的值,这里用有颜色的线表示。测试数据如右下表所示,满足多重条件覆盖准测。共8种组合条件:(1)A1,B=0(2)A1,B0(3)A1,B=0(4)A1,B0(5)A=2,X1(6)A=2,X1(7)A2,X1(8)A2,X1ABX期望204(1)(5)红线211(2)(6)绿线102(3)(7)绿线111(4)(8)蓝线入口返回A1 ANDB=0A=2 ORX1X=X/AX=X+1YYNN注意:测试数据对黄色路径并未测试到!如使第2行A=1可覆盖该路径。逻辑覆盖测试举例2022/7/1827逻辑覆

18、盖标准的适应性分析语句覆盖:查错能力最弱,一般不单独使用;判定覆盖与条件覆盖:一般情况,条件覆盖优于判断覆盖。但也可能出现:满足条件覆盖,但却不满足判断覆盖的情况。判定/条件覆盖:弥补条件覆盖的缺陷;条件组合覆盖:在5种覆盖中查错能力最强,凡是满足条件组合覆盖的测试数据,必然满足其余4种覆盖。2022/7/1828例子:按逻辑覆盖标准的要求设计冒泡程序的测试用例输入:k(序列长度),Ak(无序数据)输出:Ak(有序数据) FOR i:=2 TO k DO IF ai = ai-1 THEN FOR j:=i DOWNTO 2 DO IF aj = aj-1 THEN temp := aj; a

19、j := aj-1; aj-1 := temp; ENDIF ENDDO ENDIF ENDDO2022/7/18291) 语句覆盖:每条语句至少执行1次。测试用例:A=8,4,K=2,可满足程序执行时遍历流程图所有框的要求。潜在问题:若2个判定框中的“=”误写为“AI-1、AI=AI-1、AIAJ-1、AJ=AJ-1、AJAJ-1的情况至少出现一次。测试用例:A=8,4,9,6,K=4、A=8,4,8,4, K=4。 可合并为:A=8,4,8,4,9,6,K=64) 判定/条件覆盖:同时满足判定覆盖和条件覆盖的要求。 分析:该例中的2个复合判断条件(=)并不独立,即若为“真”,则必为“假”,

20、反之亦然。故考虑判定/条件覆盖没有实际意义。5)条件组合覆盖:求出判定中所有条件的各种可能的组合值,每一可能的条件组合至少执行1次。 分析:同上,考虑条件组合覆盖没有实际意义。例子:按逻辑覆盖标准的要求设计冒泡程序的测试用例2022/7/1831组合条件测试的路径选择当程序中判定多于一个时,形成的分支结构可分为嵌套型分支结构和连锁型分支结构。对于嵌套型分支结构,若有n个判定语句,需要n+1个测试用例;对于连锁型分支结构, 若有n个判定语句,需要有2n个测试用例,覆盖它的2n条路径。2022/7/1832组合条件测试的路径选择33Loop TestingNested LoopsConcatena

21、ted (连锁型)Loops Unstructured LoopsSimple loop34Loop Testing: Simple LoopsMinimum conditionsSimple Loops1. skip the loop entirely2. only one pass through the loop3. two passes through the loop4. m passes through the loop m n5. (n-1), n, and (n+1) passes through the loopwhere n is the maximum number of

22、 allowable passes35Loop Testing: Nested LoopsStart at the innermost loop. Set all outer loops to their minimum iteration parameter values.Test the min+1, typical, max-1 and max for the innermost loop, while holding the outer loops at their minimum values.Move out one loop and set it up as in step 2,

23、 holding all other loops at typical values. Continue this step until the outermost loop has been tested.If the loops are independent of one another then treat each as a simple loop else* treat as nested loopsendif* for example, the final loop counter value of loop 1 is used to initialize loop 2.Nest

24、ed LoopsConcatenated Loops36Black-Box Testingrequirementseventsinputoutput37Black-Box TestingHow is functional validity tested?How is system behavior and performance tested?What classes of input will make good test cases?Is the system particularly sensitive to certain input values?How are the bounda

25、ries of a data class isolated?What data rates and data volume can the system tolerate?What effect will specific combinations of data have on system operation?38Black-Box TestingBlack-box testing attempts to find errors in the following categories: incorrect or missing functionsinterface errorserrors

26、 in data structures or external database accessbehavior or performance errors39Equivalence Partitioning(等价类划分)userqueriesmousepicksoutputformatspromptsFKinputdataEquivalence partitioning is a black-box testing method that divides the input domain of a program into classes of data from which test cas

27、es can be derived. An ideal test case uncovers a class of errorsEquivalence Partitioning等价类划分 把全部输入数据合理划分为若干等价类,使每一等价类中的任何一个测试用例,都能代表该类中的其它测试用例。从而可用少量代表性测试数据,取得较好的测试效果。用例设计要点:在设计测试用例时,必须同时考虑有效等价类和无效等价类;每一无效等价类至少用一个测试用例,但允许若干有效等价类合用一个测试用例。4041Sample Equivalence Classesuser supplied commandsresponses

28、to system promptsfile namescomputational data physical parameters bounding values initiation valuesoutput data formattingresponses to error messagesgraphical data (e.g., mouse picks)data outside bounds of the program physically impossible dataproper value supplied in wrong placeValid dataInvalid dat

29、a42例:一个程序的功能描述如下,用等价类划分法设计测试用例。功能描述:某城市的电话号码由3部分组成。要求被测程序能接收一切符合下述规定的电话号码,拒绝所有不符合规定的电话号码。区号:空白或3位数字;前缀:非0或1开头的4位数字;后缀:4位数字。输入条件有效等价类无效等价类区码空白(1);3位数字(2)有非数字字符(5);少于3位数字(6);多于3位数字(7) 前缀从2000到9999的3位数字(3)有非数字字符(8);少于4位数字(9);多于4位数字(10)起始位为0(11); 起始位为1(12)后缀4位数字(4)有非数字字符(13);少于4位数字(14);多于4位数字(15)测试用例测试范

30、围期望结果 6510 2345等价类(1) (3) (4) 有效023 6511 1321等价类(2) (3) (4)有效20# 1234 4356等价类(5)无效剩下的10个用例无效等价类(6)-(15) 无效测试用例的设计:43Boundary Value Analysis(边界值分析)userqueriesmousepicksoutputformatspromptsFKinputdataoutputdomaininput domainA greater number of errors occurs at the boundaries of the input domain rather than in the “center.” Boundary value analysis leads to a selection of test cases that exercise bounding val

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论