软件测试ST02_Graph_Coverage.pptx_第1页
软件测试ST02_Graph_Coverage.pptx_第2页
软件测试ST02_Graph_Coverage.pptx_第3页
软件测试ST02_Graph_Coverage.pptx_第4页
软件测试ST02_Graph_Coverage.pptx_第5页
已阅读5页,还剩284页未读 继续免费阅读

下载本文档

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

文档简介

1、软件测试与质量保证,魏培阳 ,申明:本课件是在原书作者课件基础上编制,仅用于课堂教学,不得用于任何商业目的的活动。,1,Paul Ammann x = x + 1; else x = y; ,if (x y) y = 0; x = x + 1; ,72,控制流图: if 语句,if (x y) y = 0; x = x + 1; else x = y; ,if (x y) y = 0; x = x + 1; ,73,CFG : The if-return Statement,if (x y) return; print (x); return;,74,控制流图 : if-return 语句,i

2、f (x y) return; print (x); return;,75,Loops,Loops require “extra” nodes to be added Nodes that do not represent statements or basic blocks,76,循环,循环需要添加“额外的”节点 节点不代表语句或基本块,77,CFG : while and for Loops,x = 0; while (x y) y = f (x, y); x = x + 1; ,for (x = 0; x y; x+) y = f (x, y); ,x = x + 1,implicitl

3、y increments loop,78,控制流图 : while 和 for 循环,x = 0; while (x y) y = f (x, y); x = x + 1; ,for (x = 0; x y; x+) y = f (x, y); ,x = x + 1,隐式增量循环,79,CFG : do Loop, break and continue,x = 0; do y = f (x, y); x = x + 1; while (x y); println (y),x = 0,3,2,x = y,x y,y = f (x, y) x = x+1,1,x = 0,x = x + 1,bre

4、ak,y 0,y =f(x,y),y = 0,y = y*2 continue,x = 0; while (x y) y = f (x, y); if (y = 0) break; else if (y 0) y = y*2; continue; x = x + 1; print (y);,80,控制流图: do Loop, break 和 continue,x = 0; do y = f (x, y); x = x + 1; while (x y); println (y),x = 0,3,2,x = y,x y,y = f (x, y) x = x+1,1,x = 0,x = x + 1,

5、break,y 0,y =f(x,y),y = 0,y = y*2 continue,x = 0; while (x y) y = f (x, y); if (y = 0) break; else if (y 0) y = y*2; continue; x = x + 1; print (y);,81,CFG : The Case (switch) Structure,read ( c) ; switch ( c ) case N: y = 25; break; case Y: y = 50; break; default: y = 0; break; print (y);,82,控制流图 :

6、 The Case (switch) 结构,read ( c) ; switch ( c ) case N: y = 25; break; case Y: y = 50; break; default: y = 0; break; print (y);,83,84,Example Control Flow Stats,public static void computeStats (int numbers) int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0;

7、i length; i+) sum += numbers i ; med = numbers length / 2; mean = sum / (double) length; varsum = 0; for (int i = 0; i length; i+) varsum = varsum + (numbers I - mean) * (numbers I - mean); var = varsum / ( length - 1.0 ); sd = Math.sqrt ( var ); System.out.println (length: + length); System.out.pri

8、ntln (mean: + mean); System.out.println (median: + med); System.out.println (variance: + var); System.out.println (standard deviation: + sd); ,84,85,控制流图举例统计,public static void computeStats (int numbers) int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i

9、length; i+) sum += numbers i ; med = numbers length / 2; mean = sum / (double) length; varsum = 0; for (int i = 0; i length; i+) varsum = varsum + (numbers I - mean) * (numbers I - mean); var = varsum / ( length - 1.0 ); sd = Math.sqrt ( var ); System.out.println (length: + length); System.out.print

10、ln (平均值: + mean); System.out.println (中值: + med); System.out.println (方差: + var); System.out.println (标准偏差: + sd); ,85,Control Flow Graph for Stats,Introduction to Software Testing (Ch 2), , Ammann double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i length; i+) sum += numbers i ; med

11、= numbers length / 2; mean = sum / (double) length; varsum = 0; for (int i = 0; i length; i+) varsum = varsum + (numbers I - mean) * (numbers I - mean); var = varsum / ( length - 1.0 ); sd = Math.sqrt ( var ); System.out.println (length: + length); System.out.println (mean: + mean); System.out.print

12、ln (median: + med); System.out.println (variance: + var); System.out.println (standard deviation: + sd); ,i = 0,i+,i = 0,i+,86,Introduction to Software Testing (Ch 2), , Ammann double med, var, sd, mean, sum, varsum; sum = 0; for (int i = 0; i length; i+) sum += numbers i ; med = numbers length / 2;

13、 mean = sum / (double) length; varsum = 0; for (int i = 0; i length; i+) varsum = varsum + (numbers I - mean) * (numbers I - mean); var = varsum / ( length - 1.0 ); sd = Math.sqrt ( var ); System.out.println (length: + length); System.out.println (mean: + mean); System.out.println (median: + med); S

14、ystem.out.println (variance: + var); System.out.println (standard deviation: + sd); ,i = 0,i+,i = 0,i+,Control Flow TRs and Test Paths EC,88,控制流和测试路径 边覆盖,89,Introduction to Software Testing (Ch 2), , Ammann ) x is an actual parameter in a call and the method changes its value x is a formal parameter

15、 of a method (implicit def when method starts) x is an input to a program use : a location where variables value is accessed x appears on the right side of an assignment x appears in a conditional test x is an actual parameter to a method x is an output of the program x is an output of a method in a

16、 return statement If a def and a use appear on the same node, then it is only a DU-pair if the def occurs after the use and the node is in a loop,94,源代码数据流覆盖,def:一个位置的值被存储到内存中 x出现在一个赋值语句的左边(x = 44。) 在调用时x是一个实际参数,并且它的值在该方法中被改变 x是一个方法的形式参数(当方法开始执行时是一个隐式的def) x是一个程序的输入 use:一个位置访问变量的值 x出现在一个赋值语句的右边 x出现在

17、条件测试中(注意此种测试总是关联至少两条边) x是一个方法的实际参数 x是程序的输出 x在return语句中是一个方法的输出 如果一个def和一个use出现在同一个节点, 如果def在use后发生并且节点在一个循环中,那么它只是一个DU对,95,Example Data Flow Stats,public static void computeStats (int numbers) int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0.0; for (int i = 0; i length; i

18、+) sum += numbers i ; med = numbers length / 2 ; mean = sum / (double) length; varsum = 0.o; for (int i = 0; i length; i+) varsum = varsum + (numbers i - mean) * (numbers i - mean); var = varsum / ( length - 1 ); sd = Math.sqrt ( var ); System.out.println (length: + length); System.out.println (mean

19、: + mean); System.out.println (median: + med); System.out.println (variance: + var); System.out.println (standard deviation: + sd); ,96,数据流举例 统计,public static void computeStats (int numbers) int length = numbers.length; double med, var, sd, mean, sum, varsum; sum = 0.0; for (int i = 0; i length; i+)

20、 sum += numbers i ; med = numbers length / 2 ; mean = sum / (double) length; varsum = 0.o; for (int i = 0; i length; i+) varsum = varsum + (numbers i - mean) * (numbers i - mean); var = varsum / ( length - 1 ); sd = Math.sqrt ( var ); System.out.println (“长度: + length); System.out.println (“平均值 + me

21、an); System.out.println (“中间值: + med); System.out.println (方差: + var); System.out.println (标准差: + sd); ,97,Control Flow Graph for Stats,( numbers ) sum = 0 length = numbers.length,i = 0,sum += numbers i i+,med = numbers length / 2 mean = sum / (double) length varsum = 0 i = 0,varsum = i+,var = varsu

22、m / ( length - 1.0 ) sd = Math.sqrt ( var ) print (length, mean, med, var, sd),98,统计的控制流图,( numbers ) sum = 0 length = numbers.length,i = 0,sum += numbers i i+,med = numbers length / 2 mean = sum / (double) length varsum = 0 i = 0,varsum = i+,var = varsum / ( length - 1.0 ) sd = Math.sqrt ( var ) pr

23、int (length, mean, med, var, sd),99,CFG for Stats With Defs ,故障被发现,111,Summary,Applying the graph test criteria to control flow graphs is relatively straightforward Most of the developmental research work was done with CFGs A few subtle decisions must be made to translate control structures into the

24、 graph Some tools will assign each statement to a unique node These slides and the book uses basic blocks Coverage is the same, although the bookkeeping will differ,112,小结,应用图测试标准到控制流程图中相对简单 大多数的开发研究工作用CFG完成 一些细微判断条件必须要在控制结构转换图中体现 一些工具将会分配每个语句给一个独立节点 课件和教科书使用的是基本块 进行覆盖结果是相同的,只是记录测试的方式将有所不同,113,OUTLI

25、NE,114,大纲,115,OO Software and Designs,Emphasis on modularity and reuse puts complexity in the design connections Testing design relationships is more important than before Graphs are based on the connections among the software components Connections are dependency relations, also called couplings,11

26、6,面向对象软件与设计,在关系设计中强调模型化和重用表达复杂性 测试设计的关系比以前更重要 图基于软件组件之间的关系 连接是依赖关系,也称为耦合,117,Call Graph,The most common graph for structural design testing Nodes : Units (in Java methods) Edges : Calls to units,Node coverage : call every unit at least once (method coverage),Edge coverage : execute every call at lea

27、st once (call coverage),118,图调用,最常见的图结构设计测试 节点:单元(在Java中指方法) 边:调用单元,119,节点覆盖:调用每个单元至少一次(方法覆盖),边覆盖:执行每个调用至少一次(调用覆盖),Call Graphs on Classes,Node and edge coverage of class call graphs often do not work very well Individual methods might not call each other at all!,Class stack public void push (Object

28、o) public Object pop ( ) public boolean isEmpty (Object o),Other types of testing are needed do not use graph criteria,120,在类上调用图,类的节点和边覆盖调用图通常不会做的很好 单个方法不可能会互相调用!,121,类栈 public void push (Object o) public Object pop ( ) public boolean isEmpty (Object o),其他类型的测试是必要的不使用图形标准,Inheritance 3 4 class Quad

29、ratic5 6 private static float Root1, Root2;78 public static void main (String argv)9 10 int X, Y, Z;11 boolean ok;12 int controlFlag = Integer.parseInt (argv0);13 if (controlFlag = 1)14 15 X = Integer.parseInt (argv1);16 Y = Integer.parseInt (argv2);17 Z = Integer.parseInt (argv3);18 19 else20 21 X

30、= 10;22 Y = 9;23 Z = 12;24 ,25 ok = Root (X, Y, Z);26 if (ok)27 System.out.println28 (“Quadratic: ” + Root1 + Root2);29 else30 System.out.println (“No Solution.”);31 3233 / Three positive integers, finds quadratic root34 private static boolean Root (int A, int B, int C)35 36 float D;37 boolean Resul

31、t;38 D = (float) Math.pow (double)B, (double2-4.0)*A*C );39 if (D 0.0)40 41 Result = false; 42 return (Result);43 44 Root1 = (float) (-B + Math.sqrt(D)/(2.0*A);45 Root2 = (float) (-B Math.sqrt(D)/(2.0*A);46 Result = true;47 return (Result);48 / /End method Root4950 / End class Quadratic,1 / Program

32、to compute the quadratic root for two numbers2 import java.lang.Math;3 4 class Quadratic5 6 private static float Root1, Root2;78 public static void main (String argv)9 10 int X, Y, Z;11 boolean ok;12 int controlFlag = Integer.parseInt (argv0);13 if (controlFlag = 1)14 15 X = Integer.parseInt (argv1)

33、;16 Y = Integer.parseInt (argv2);17 Z = Integer.parseInt (argv3);18 19 else20 21 X = 10;22 Y = 9;23 Z = 12;24 ,25 ok = Root (X, Y, Z);26 if (ok)27 System.out.println28 (“Quadratic: ” + Root1 + Root2);29 else30 System.out.println (“No Solution.”);31 3233 / Three positive integers, finds quadratic roo

34、t34 private static boolean Root (int A, int B, int C)35 36 float D;37 boolean Result;38 D = (float) Math.pow (double)B, 2)-(double)4.0*A*C;39 if (D 0.0)40 41 Result = false; 42 return (Result);43 44 Root1 = (float) (-B + Math.sqrt(D)/(2.0*A);45 Root2 = (float) (-B Math.sqrt(D)/(2.0*A);46 Result = tr

35、ue;47 return (Result);48 / /End method Root4950 / End class Quadratic,举例二次方根,135,1 / Program to compute the quadratic root for two numbers2 import java.lang.Math;3 4 class Quadratic5 6 private static float Root1, Root2;78 public static void main (String argv)9 10 int X, Y, Z;11 boolean ok;12 int con

36、trolFlag = Integer.parseInt (argv0);13 if (controlFlag = 1)14 15 X = Integer.parseInt (argv1);16 Y = Integer.parseInt (argv2);17 Z = Integer.parseInt (argv3);18 19 else20 21 X = 10;22 Y = 9;23 Z = 12;24 ,136,1 / Program to compute the quadratic root for two numbers2 import java.lang.Math;3 4 class Q

37、uadratic5 6 private static float Root1, Root2;78 public static void main (String argv)9 10 int X, Y, Z;11 boolean ok;12 int controlFlag = Integer.parseInt (argv0);13 if (controlFlag = 1)14 15 X = Integer.parseInt (argv1);16 Y = Integer.parseInt (argv2);17 Z = Integer.parseInt (argv3);18 19 else20 21

38、 X = 10;22 Y = 9;23 Z = 12;24 ,137,25 ok = Root (X, Y, Z);26 if (ok)27 System.out.println28 (“Quadratic: ” + Root1 + Root2);29 else30 System.out.println (“No Solution.”);31 3233 / Three positive integers, finds the quadratic root34 private static boolean Root (int A, int B, int C)35 36 float D;37 bo

39、olean Result;38 D = (float) Math.pow (double)B, (double2-4.0)*A*C);39 if (D 0.0)40 41 Result = false; 42 return (Result);43 44 Root1 = (float) (-B + Math.sqrt(D) / (2.0*A);45 Root2 = (float) (-B Math.sqrt(D) / (2.0*A);46 Result = true;47 return (Result);48 / /End method Root4950 / End class Quadrati

40、c,138,25 ok = Root (X, Y, Z);26 if (ok)27 System.out.println28 (“Quadratic: ” + Root1 + Root2);29 else30 System.out.println (“No Solution.”);31 3233 / Three positive integers, finds the quadratic root34 private static boolean Root (int A, int B, int C)35 36 float D;37 boolean Result;38 D = (float) M

41、ath.pow (double)B, (double2-4.0)*A*C);39 if (D 0.0)40 41 Result = false; 42 return (Result);43 44 Root1 = (float) (-B + Math.sqrt(D) / (2.0*A);45 Root2 = (float) (-B Math.sqrt(D) / (2.0*A);46 Result = true;47 return (Result);48 / /End method Root4950 / End class Quadratic,139,Quadratic Coupling DU-p

42、airs,Pairs of locations: method name, variable name, statement (main (), X, 15) (Root (), A, 38) (main (), Y, 16) (Root (), B, 38) (main (), Z, 17) (Root (), C, 38) (main (), X, 21) (Root (), A, 38) (main (), Y, 22) (Root (), B, 38) (main (), Z, 23) (Root (), C, 38) (Root (), Root1, 44) (main (), Ro

43、ot1, 28) (Root (), Root2, 45) (main (), Root2, 28) (Root (), Result, 41) ( main (), ok, 26 ) (Root (), Result, 46) ( main (), ok, 26 ),140,二次方根-耦合du对,本地对: 方法名, 变量名,语句行号 (main (), X, 15) (Root (), A, 38) (main (), Y, 16) (Root (), B, 38) (main (), Z, 17) (Root (), C, 38) (main (), X, 21) (Root (), A,

44、 38) (main (), Y, 22) (Root (), B, 38) (main (), Z, 23) (Root (), C, 38) (Root (), Root1, 44) (main (), Root1, 28) (Root (), Root2, 45) (main (), Root2, 28) (Root (), Result, 41) ( main (), ok, 26 ) (Root (), Result, 46) ( main (), ok, 26 ),141,Coupling Data Flow Notes,Only variables that are used o

45、r defined in the callee,Implicit initializations of class and global variables Transitive DU-pairs are too expensive to handle A calls B, B calls C, and there is a variable defined in A and used in C Arrays : a reference to one element is considered to be a reference to all elements,142,耦合数据流节点,只有变量

46、在被调用者中使用或定义,类隐式初始化和全局变量 传递du对处理过于昂贵 A调用B,B调用C,并且A中存在一个变量定义,并且C中有一个使用 数组:一个对元素的引用被认为是对所有元素的引用,143,Inheritance, Polymorphism Actual type : The type used in the object assignment: obj = new B(); Class (State) Variables : The variables declared at the class level, often private,146,附加的定义,附加的定义继承:如果B类继承自

47、类A,然后A中所有的变量和方法在隐式地出现在B中,并且B可以添加更多的变量和方法 A是父类或祖先 B是子类或派生的 一个将被声明为类A的对象引用obj,可被分配任何一种类A的对象,B或任何的B子类的对象 声明类型:类型用于声明:A obj; 实际类型:使用类型的对象分配:obj = new B(); 类(静态)变量:变量在类级声明,经常是私有的,147,Types of Def-Use Pairs,148,DU对的类型,149,OO Data Flow Summary,The defs and uses could be in the same class, or different clas

48、ses Researchers have applied data flow testing to the direct coupling OO situation Has not been used in practice No tools available Indirect coupling data flow testing has not been tried either in research or in practice Analysis cost may be prohibitive,150,面向对象数据流总结,在def和use可在同一类中,或者不同的类中 研究人员已经应用了

49、数据流测试面向对象直接耦合的情况 没有被用于实践 没有工具可用 间接耦合数据流测试在研究或在实践中尚未尝试过 分析成本可能过高,151,Web Applications and Other Distributed Software,distributed software data flow,“message” could be HTTP, RMI, or other mechanism A() and B() could be in the same class or accessing apersistent variable such as in a web session Beyond

50、 current technologies,152,Web应用程序和其他的分布式软件,“消息”可能是HTTP、RMI、或其他机制 A()和B()可以在同一个类或访问一个持久变量比如在web中的一个会话 超出现有技术,153,分布式软件数据流,SummaryWhat Works?,Using sequence constraints is an easy way to design effective tests The act of creating sequence constraints will often find problems Call graphs are common and

51、 very useful ways to design integration tests Inter-procedural data flow is relatively easy to compute and results in effective integration tests The ideas for OO software and web applications are preliminary and have not been used much in practice,154,总结什么在起作用?,使用序列约束是一个设计有效测试的简单方法 创建序列约束的行为将经常发现问题

52、 调用图表是设计集成测试常见的和非常有用方法 内部程序化数据流相对容易计算,并且结果有效的集成测试 面向软件思想和web应用程序是初步措施,在实践中没有被大量使用,155,OUTLINE,156,大纲,157,Design Specifications,A design specification describes aspects of what behavior software should exhibit A design specification may or may not reflect the implementation More accurately the implem

53、entation may not exactly reflect the spec Design specifications are often called models of the software Two types of descriptions are used in this chapter Sequencing constraints on class methods State behavior descriptions of software,158,设计规范,一个设计规范描述了什么行为是软件应该展现的面貌 一个设计规格可能会也可能不会反映实现 更准确地说实现可能不会完全

54、反映该规范 设计规格通常被称为软件的模型 两种类型描述在这一章中使用 类方法的顺序约束 软件的状态行为描述,159,Sequencing Constraints,Sequencing constraints are rules that impose constraints on the order in which methods may be called They can be encoded as preconditions or other specifications Section 2.4 said that classes often have methods that do

55、not call each other,Tests can be created for these classes as sequences of method calls Sequencing constraints give an easy and effective way to choose which sequences to use,160,顺序约束,顺序约束就是一条规则,它在某些方法的调用顺序上施加了某种限制 它们可作为先决条件或其他规范来编码 2.4节讲过,类常有方法,它们彼此不调用,161,测试被创建用于这些类方法调用序列 顺序约束给出一个简单而有效地方式来选择使用哪个序列

56、,Sequencing Constraints Overview,Sequencing constraints might be Expressed explicitly Expressed implicitly Not expressed at all Testers should derive them if they do not exist Look at existing design documents Look at requirements documents Ask the developers Last choice : Look at the implementation

57、 If they dont exist, expect to find more faults ! Remember that sequencing constraints do not capture all behavior,162,顺序约束概述,顺序约束可能 明确表达 隐式表达 没有表达 测试人员推导它们,如果它们不存在 看看现有的设计文档 看看需求文档 问问开发人员 最后的选择:看看这个实现 如果它们不存在,期望找到更多的错误! 记住,顺序约束不会捕获所有的行为,163,Queue Example,Sequencing constraints are implicitly embedded in the pre and postconditions EnQueue () must be called before DeQueue () Does not include the requirement that we must have at least as many Enqueue () calls as DeQueue () calls Can be handled by state behavior

温馨提示

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

评论

0/150

提交评论