Chapter 6 Path Testing Software Testing

Slides:



Advertisements
Similar presentations
Software Testing Techniques
Advertisements

Chapter 14 Software Testing Techniques - Testing fundamentals - White-box testing - Black-box testing - Object-oriented testing methods (Source: Pressman,
Chapter 14 Testing Tactics
Chapter 2: Boundary Value Testing : BVT Software Testing
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Path Testing Basics By Chandra Kumar R Date : 20-Nov-2004.
CYCLOMATIC COMPLEXITY 1. Invented by Thomas McCabe (1974) to measure the complexity of a program ’ s conditional logic Cyclomatic complexity of graph.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
SIM5102 SOFTWARE EVALUATION
White Box Testing Techniques Dynamic Testing. White box testing(1) Source code is known and used for test design While executing the test cases, the internal.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
BASIS PATH TESTING ● By Tom McCabe ● McCabe, T., "A Software Complexity Measure," IEEE Trans. Software Engineering, vol. SE-2, December 1976, pp
Chapter 18 Testing Conventional Applications
Unit Testing CS 414 – Software Engineering I Don Bagert Rose-Hulman Institute of Technology January 16, 2003.
The Program Design Phases
Path testing Path testing is a “design structural testing” in that it is based on detailed design & the source code of the program to be tested. The methodology.
Cyclomatic Complexity Dan Fleck Fall 2009 Dan Fleck Fall 2009.
Software Systems Verification and Validation Laboratory Assignment 3
Testing phases. Test data Inputs which have been devised to test the system Test cases Inputs to test the system and the predicted outputs from these.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 20 Slide 1 Defect testing l Testing programs to establish the presence of system defects.
Path Testing + Coverage Chapter 9 Assigned reading from Binder.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
Agenda Introduction Overview of White-box testing Basis path testing
1 Software Testing. 2 Path Testing 3 Structural Testing Also known as glass box, structural, clear box and white box testing. A software testing technique.
Software Life Cycle What Requirements Gathering, Problem definition
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
INTRUDUCTION TO SOFTWARE TESTING TECHNIQUES BY PRADEEP I.
White-box Testing.
Software Testing and Reliability Southern Methodist University CSE 7314.
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
COMP 6710 Course NotesSlide 7-0 Auburn University Computer Science and Software Engineering Course Notes Set 7: Review of Graphs Computer Science and Software.
BASIS PATH TESTING.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
Theory and Practice of Software Testing
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
White Box Testing by : Andika Bayu H.
Cyclomatic complexity (or conditional complexity) is a software metric (measurement). Its gives the number of indepented paths through strongly connected.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Cyclomatic Complexity Philippe CHARMAN Last update:
Software Testing Techniques Presented By Dr. Shazzad Hosain.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
White-Box Testing Statement coverage Branch coverage Path coverage
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Software Test Metrics When you can measure what you are speaking about and express it in numbers, you know something about it; but when you cannot measure,
Lab 7 Control-Flow Testing
PREPARED BY G.VIJAYA KUMAR ASST.PROFESSOR
BASIS PATH TESTING.
Software Testing.
Software Testing.
Software Engineering (CSI 321)
Structural testing, Path Testing
Types of Testing Visit to more Learning Resources.
White Box Testing.
Programming Fundamentals
Chapter 9 Path Testing–Part 1
Software Testing (Lecture 11-a)
Chapter 14 Software Testing Techniques
Halstead software science measures and other metrics for source code
Solution to problem 4. a) Control flow graph art Start k = i + 2 * j
Program Flow.
Coursework 1 Due Tuesday, Feb 6, 2007 in the tutorial
Basic Concepts of Algorithm
Whitebox Testing.
By: Lecturer Raoof Talal
Unit III – Chapter 3 Path Testing.
Presentation transcript:

Chapter 6 Path Testing 322 235 Software Testing By Wararat Songpan(Rungworawut),PH.D. Department of Computer Science, Faculty of Science, Khon Kaen University

Path Testing Path testing is a Structural Testing method that involves using the source code of a program to attempt to find every possible executable path. The idea is that are able to test each individual path from source code is as many way as possible in order to maximize the coverage of each test case. Therefore, we use knowledge of the source code to define the test cases and to examine outputs. Test cases derived to exercise the basis set are guaranteed to execute every statement in the program at least one time during testing

Flow Graph Given a program written in an imperative programming language, its program graph is a directed graph in which nodes are statement fragments, and edges represent flow of control It may be called “Control Flow Graph”

Flow chart & Flow Graph Flow Chart Flow Graph 1 1 2 2 3 3 6 4 6 4 7 8 5 7 8 5 9 9 11 10 11 10

Flow Graph Notation Notation Description A circle in a graph represents a node, which stands for a sequence of one or more procedural statements A node containing a simple conditional expression is referred to as a predicate node which has two edges leading out from it (True and False) An edge, or a link, is a an arrow representing flow of control in a specific direction - An edge must start and terminate at a node - An edge does not intersect or cross over another edge 322 235 การทดสอบซอฟต์แวร์

Flow Graph Example(1) 2 3 4 5 6 7 8 9 10 Program ‘Simple Subtraction’ Input(x,y) Output (x) Output(y) If x> y then Do x-y = z Else y-x = z EndIf Output(z) Output “End Program” 3 4 5 6 7 8 9 10 322 235 การทดสอบซอฟต์แวร์

Flow Graphs consist of 2 A decision is a program point at which the control can diverge. (e.g., if and case statements) 3 4 5 6 7 N Y Y 8 N Switch case 9 While Loop Until Loop 10

Flow Graphs consist of 2 A junction is a program point where the control flow can merge. (e.g., end if , end loop, goto label) 3 4 5 6 7 Goto 8 Connector 9 10

Flow Graphs consist of 2 A process block is a sequence of program statements uninterrupted by either decisions of junction. (i.e. straight-line code) 3 4 5 Sequence 6 7 8 9 10 322 235 การทดสอบซอฟต์แวร์

Flow Graph Example(2) 1 2 3 4 5 6 7 8 9 10 11 scanf(“%d %d”,&x, &y); If (y<0) pow = -y; else 4. pow = y; Z = 1.0 While (pow != 0) { z = z*x; pow = pow -1; } If (y <0) z = 1.0 /z; printf(“%f”,z); 3 4 5 6 7 8 9 10 11

What is Path? A path through a program is a sequence of statements that starts at an entry, junctions, or decision and ends. A path may go through several junctions, processes, or decisions, on or more times. Paths consist of segments that has smallest segment is a link between 2 nodes. 322 235 การทดสอบซอฟต์แวร์

What is Path? 2 3 4 5 6 7 8 9 10 For example: Path1 = 2-3-4-5-6-8-9-10 12

What is Path? 2 3 4 5 6 7 8 9 10 For example: Path2 = 2-3-4-5-7-8-9-10 13

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i 8 j 9

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i 8 j 9

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

Path Testing Strategies Statement Testing 100% statement / node coverage Branch Testing 100% branch/ link coverage Path Testing 100% path coverage 1 a 2 b T F c 3 4 d e 5 T F f g 6 7 h i Statement Testing < Branch Testing < Path Testing 8 j 9

A Coverage Table Paths Decisions Process-Link 2 5 a b c d e f g h i j 1-2-3-5-6-8-9 (a-b-d-f-h-j) T  1-2-4-5-7-8-9 (a-c-e-g-i-j) F 1-2-3-5-7-8-9 (a-b-d-g-i-j) 1-2-4-5-6-8-9 (a-c-e-f-h-j) 1 a 2 b c T F 3 4 d e 5 f T F g 6 7 h i 8 j 9 20 322 235 การทดสอบซอฟต์แวร์

Exmple Flow Graph Flow Graph 1. Program Triangle 2. Dim a, b,c As Integer 3. Dim IsTriangle As Boolean 4. Output ( “enter a,b, and c integers”) 5. Input (a,b,c) 6. Output (“side 1 is”, a) 7. Output (“side 2 is”, b) 8. Output (”side 3 is”, c) 9. If (a<b+c) AND (b<a+c) And (c<b+a) 10. then IsTriangle = True 11. else IsTriangle = False 12. endif 13. If IsTriangle 14. then if (a=b) AND (b=c) 15. then Output (“equilateral”) 16. else if (a != b) AND (a != b) AND (b != c) 17. then Output ( “Scalene”) 18. else Output (“Isosceles”) 19. endif 20. endif 21. else Output (“not a triangle”) 22. endif 23. end Triangle2 4 5 6 7 8 9 Flow Graph 10 11 12 13 21 14 15 16 17 18 20 19 22 23

Basis Path Testing Select Path is shortest or simple path For example: 4 5 6 7 8 Select Path is shortest or simple path For example: 4-5-6-7-8-9-10-12-13-21-22-23 9 10 11 12 13 21 14 15 16 17 18 20 19 22 23 22 322 235 การทดสอบซอฟต์แวร์

Test Case for Path Coverage  4-5-6-7-8-9-10-12-13-21-22-23 4-5-6-7-8-9-11-12-13-14-15-20-22-23  4-5-6-7-8-9-11-12-13-14-16-17-19-20-22-23  4-5-6-7-8-9-11-12-13-14-16-18-19-20-22-23 Path Decision Test case Expected Results 9 13 14 16 a b c  T F 100 200 Not A triangle  Equilateral  50 60 Scalene  Isosceles

DD-Paths It stand for Decision-to-Decision path in a directed graph. A path are consists of the initial and nodes and interior node has indegree = 1 and outdegree = 1 indegree =1 outdegree =1

DD-Paths Characteristic of DD-Path has 5 cases: Case 1: Single node with indeg =0 Case 2: Single node with outdeg = 0 Case 3: Single node with indeg >= 2 or outdeg >=2 Case 4: Single node with indeg = 1 and outdeg =1 Case 5: Maximum chain of length >=1 25 322 235 การทดสอบซอฟต์แวร์

Condensation of Code to Table then to Flow Graph Path/node name DD-path Case code statement 1. Program Triangle 2. Dim a, b,c As Integer 3. Dim IsTriangle As Boolean 4. Output ( “enter a,b, and c integers”) 5. Input (a,b,c) 6. Output (“side 1 is”, a) 7. Output (“side 2 is”, b) 8. Output (”side 3 is”, c) 9. If (a<b+c) AND (b<a+c) And (c<b+a) 10. then IsTriangle = True 11. else IsTriangle = False 12. endif 13. If IsTriangle 14. then if (a=b) AND (b=c) 15. then Output (“equilateral”) 16. else if (a NE b) AND (a NE b) AND (b NE c) 17. then Output ( “Scalene”) 18. else Output (“Isosceles”) 19. endif 20. endif 21. else Output (“not a triangle”) 22. endif 23. end Triangle2 Skip 1- 3 (or w/4) 4 first 1 5 – 8 A 5 9 B 3 10 C 4 11 D 4 12 E 3 13 F 3 14 H 3 15 I 4 16 J 3 17 K 4 18 L 4 19 M 3 20 N 3 21 G 4 22 O 3 23 last 2 Def of DD-paths on

DD-Path First 4 5 6 7 8 A 9 B 10 11 C D 12 E 13 F 21 14 G H 15 16 I J 17 18 K L 20 19 N M 22 O 23 Last

Path Analysis What is path analysis? Analyzes the number of paths that exist in the system Facilitates the decision process of how many paths to include in the test

Path Analysis: Cyclomatic complexity measure (CFC) CFC can be calculated by V(G) = e-n+2 e : the number of edges n : the number of nodes Example: = 10-7+2 = 5 A B D F T E F T C F G

Path Analysis: Cyclomatic complexity measure (CFC) If flow graph has link between sink node(G) to source node(A) which is called a strongly connected graph. V(G) = e-n+1 e : the number of edges n : the number of nodes Example: 11-7+1 = 5 A B D F T T E F C F G 30 322 235 การทดสอบซอฟต์แวร์

How to select path Independent Path McCabe’s Baseline 322 235 การทดสอบซอฟต์แวร์

Independent Path A B D E C F G Independent program paths an independent path is any path through the program that introduces at least one new set of processing statements or a new condition. Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity if a program No count on traverse edge between sink node-G to source node-A P1: A-B-C-G P2: A-B-C-B-C-G P3: A-B-E-F-G P4: A-D-E-F-G P5: A-D-F-G A B D F T E T F C F G

Independent Path Problem of Independent path A B D E C F G P1: A-B-C-G P2: A-B-C-B-C-G P3: A-B-E-F-G P4: A-D-E-F-G P5: A-D-F-G Ex1: A-B-C-B-E-F-G Ex2: A-B-C-B-C-B-C-G A B D F T E T F C F G

McCabe’s Baseline To determine a set of basis paths, 1. Pick a "baseline" path that corresponds to normal execution. (The baseline should have as many decisions as possible.) 2. To get succeeding basis paths, retrace the baseline until you reach a decision node. "Flip" the decision (take another alternative) and continue as much of the baseline as possible. 3. Repeat this until all decisions have been flipped. When you reach V(G) basis paths, you're done. 4. If there aren't enough decisions in the first baseline path, find a second baseline and repeat steps 2 and 3.

McCabe’s Baseline A B D E C F G P1: A-B-C-B-E-F-G P2: A-D-E-F-G P3: A-D-F-G P4: A-B-E-F-G P5: A-B-C-G A B D F T E T F C F G

McCabe’s Path of Triangle Program First McCabe Paths Expected Results Original P1: First-A-B-C-E-F-H-J-K-M-N-O-Last Scalene Flip P1 at B P2: First-A-B-D-E-F-H-J-K-M-N-O-Last Infeasible path Flip P1 at F P3: First-A-B-C-E-F-G-O-Last Flip P1 at H P4: First-A-B-C-E-F-H-I-N-O-Last Equilateral Flip P1 at J P5: First-A-B-C-E-F-H-J-L-M-N-O-Last Isosceles A B C D E F G H I J K L N M O Last

McCabe’s Path Weakness of McCabe’s Path may occur “infeasible path” which means no found test case design to match with the path. McCabe Paths Expected Results P1 Original P1: First-A-B-C-E-F-H-J-K-M-N-O-Last Scalene P6(from P2 and P3) New P6: First-A-B-D-E-F-G-O-Last Not a Triangle P4 Flip P1 at H P4: First-A-B-C-E-F-H-I-N-O-Last Equilateral P5 Flip P1 at J P5: First-A-B-C-E-F-H-J-L-M-N-O-Last Isosceles

From path analysis to test case design b c Expected Results From Path 1 3 4 5 Scalene P1 2 Not a Triangle P6 Equilateral P4 Isosceles P5

Steps of path testing Deriving Test Cases Using the design or code, draw the corresponding flow graph. Determine the cyclomatic complexity of the flow graph. determine a set of path by basis/independent/McCabe’s paths. Prepare test cases that will force execution of each path in the basis set.

Basis Path Testing Example    public double calculate(int amount)     { 1. double rushCharge = 0;   if (nextday.equals("yes") )      { 2.       rushCharge = 14.50; } 3  double tax = amount * .0725; 3  if (amount >= 1000) { 4.       shipcharge = amount * .06 + rushCharge; } 5. else if (amount >= 200) { 6.      shipcharge = amount * .08 + rushCharge; } 7.  else if (amount >= 100) { 8.      shipcharge = 13.25 + rushCharge; } 9.  else if (amount >= 50) { 10.      shipcharge = 9.95 + rushCharge; } 11. else if (amount >= 25) { 12.      shipcharge = 7.25 + rushCharge; }      else { 13.     shipcharge = 5.25 + rushCharge; } 14. total = amount + tax + shipcharge; 14. return total; } //end calculate  

Basis Path Testing Example 1 Here is a drawing of the flowgraph. 2 3 4 5 6 7 8 10 9 11 12 13 14

Basis Path Testing Example Step 2: Determine the cyclomatic complexity of the flow graph. V(G) = E - N + 2         = 19 - 14 + 2         =  7

Basis Path Testing Example Step 3: Determine the basis set of independent paths. Path 1:  1 - 2 - 3 - 5 - 7 - 9 - 11 - 13 - 14 Path 2:  1 - 3 - 4 - 14 Path 3:  1 - 3 - 5 - 6 - 14 Path 4:  1 - 3 - 5 - 7 - 8 - 14 Path 5:  1 - 3 - 5 - 7 - 9 - 10 - 14 Path 6:  1 - 3 - 5 - 7 - 9 - 11 - 12 - 14 Path 7:  1 - 3 - 5 - 7 - 9 - 11 - 13 - 14

Basis Path Testing Example step 4: Prepare test cases that force execution of each path in the basis set. Path Nextday Amount Expected Results P1 yes  10 30.48 P2 No 1500 1713.25 P3 300 345.75 P4 150 174.125 P5 75  90.3875 P6 30 39.425 P7 15.975