Lab 7 Control-Flow Testing

Slides:



Advertisements
Similar presentations
Lecture 2: testing Book: Chapter 9 What is testing? Testing is not showing that there are no errors in the program. Testing cannot show that the program.
Advertisements

Chapter 6 Path Testing Software Testing
Whitebox Testing Fra: CS Fall Whitebox Testing AKA Structural, Basis Path Test Normally used at unit level Assumes errors at unit level are.
Computer Science 2212a/b - UWO1 Structural Testing Motivation The gcov Tool An example using gcov How does gcov do it gcov subtleties Further structural.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Today’s Agenda  HW #1 Due  Quick Review  Finish Input Space Partitioning  Combinatorial Testing Software Testing and Maintenance 1.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Ch6: Software Verification. 1 Statement coverage criterion  Informally:  Formally:  Difficult to minimize the number of test cases and still ensure.
IMSE Week 18 White Box or Structural Testing Reading:Sommerville (4th edition) ch 22 orPressman (4th edition) ch 16.
Software Testing and Quality Assurance
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Dependable Software Systems
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Chapter 13 & 14 Software Testing Strategies and Techniques
Topics in Software Dynamic White-box Testing Part 1: Control-flow Testing [Reading assignment: Chapter 7, pp plus many things in slides that are.
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.
Topics in Software Dynamic White-box Testing: Data-flow Testing
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
System/Software Testing
© SERG Dependable Software Systems (Control-Flow Testing) Dependable Software Systems Topics in Control-Flow Testing Material drawn from [Beizer, Mancoridis]
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
GNU gcov (1/4) [from Wikipedia] gcov is a source code coverage analysis and statement- by-statement profiling tool. gcov generates exact counts of the.
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.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Software Verification Graph Model. 2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
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
Agent program is the one part(class)of Othello program. How many test cases do you have to test? Reversi [Othello]
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
1 Test Coverage Coverage can be based on: –source code –object code –model –control flow graph –(extended) finite state machines –data flow graph –requirements.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
Dynamic White-Box Testing What is code coverage? What are the different types of code coverage? How to derive test cases from control flows?
Software Dynamic White-box Testing Part 2: Data-flow Testing Lecture 7 Prof. Mostafa Abdel Aziem Mostafa.
Software Dynamic White-box Testing Lecture 6 Part 1: Control-flow Testing.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Software Testing.
Control Flow Testing Handouts
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Introduction to Software Testing Syntactic Logic Coverage Criteria
Paul Ammann & Jeff Offutt
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Chapter 13 & 14 Software Testing Strategies and Techniques
Structural testing, Path Testing
Control Flow based Testing
Lecture 2: Logical Problems with Choices
Software Testing (Lecture 11-a)
GNU gcov (1/4) [from Wikipedia]
Structured Program
SME1013 PROGRAMMING FOR ENGINEERS
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
SME1013 PROGRAMMING FOR ENGINEERS
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Computer programming Lecture 3.
GNU gcov (1/4) [from Wikipedia]
Tata Consultancy Services
COMPUTER PROGRAMMING SKILLS
COSC 4506/ITEC 3506 Software Engineering
Whitebox Testing.
CSE 1020:Software Development
CSC215 Lecture Control Flow.
Software Testing.
Software Testing and QA Theory and Practice (Chapter 5: Data Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Chapter 13 & 14 Software Testing Strategies and Techniques 1 Software Engineering: A Practitioner’s Approach, 6th edition by Roger S. Pressman.
Presentation transcript:

Lab 7 Control-Flow Testing

Control-Flow Testing Control-flow testing is a structural testing strategy that uses the program’s control flow as a model. Control-flow testing techniques are based on judiciously selecting a set of test paths through the program. The set of paths chosen is used to achieve a certain measure of testing thoroughness. E.g., pick enough paths to assure that every source statement is executed as least once.

Motivation Control-flow testing is most applicable to new software for unit testing. Control-flow testing assumptions: specifications are correct data is defined and accessed properly there are no bugs other than those that affect control flow Structured and OO languages reduce the number of control-flow bugs.

Control Flowgraphs The control flowgraph is a graphical representation of a program’s control structure. Flowgraphs Consist of Three Primitives A decision is a program point at which the control can diverge. (e.g., if and case statements). A junction is a program point where the control flow can merge. (e.g., end if, end loop, goto label) A process block is a sequence of program statements uninterrupted by either decisions or junctions. (i.e., straight-line code). A process has one entry and one exit. A program does not jump into or out of a process.

Exponentiation Algorithm 1 scanf(“%d %d”,&x, &y); 2 if (y < 0) pow = -y; else pow = y; 3 z = 1.0; 4 while (pow != 0) { z = z * x; pow = pow - 1; 5 } 6 if (y < 0) z = 1.0 / z; 7 printf (“%f”,z);

Bubble Sort Algorithm 1 for (j=1; j<N; j++) { last = N - j + 1; 2 for (k=1; k<last; k++) { 3 if (list[k] > list[k+1]) { temp = list[k]; list[k] = list[k+1]; list[k+1] = temp; 4 } 5 } 6 } 7 print(“Done\n”);

Control-flow Testing Criteria Path Testing: 100% path coverage Execute all possible control flow paths through the program. Statement Testing: 100% statement coverage. Execute all statements in a program at least once under some test. Branch Testing: 100% branch coverage. Execute enough tests to assure that every branch alternative has been exercised at least once under some test.

Two Detailed Examples of Control-flow Testing

Using Control-flow Testing to Test Function ABS Consider the following function: /* ABS This program function returns the absolute value of the integer passed to the function as a parameter. INPUT: An integer. OUTPUT: The absolute value if the input integer. */ 1 int ABS(int x) 2 { 3 if (x < 0) 4 x = -x; 5 return x; 6 }

The Flowgraph for ABS /* ABS This program function returns the absolute value of the integer passed to the function as a parameter. INPUT: An integer. OUTPUT: The absolute value if the input integer. */ 1 int ABS(int x) 2 { 3 if (x < 0) 4 x = -x; 5 return x; 6 }

Test Cases to Satisfy Path Coverage for ABS ABS takes as its input any integer. There are many integers (depending on the maximum size of an integer for the language) that could be input to ABS making it impractical to test all possible inputs to ABS.

Test Cases to Satisfy Statement Testing Coverage for ABS

Test Cases to Satisfy Branch Testing Coverage for ABS

Example: Using Control-flow Testing to Test Program COUNT Consider the following function: /* COUNT This program counts the number of characters and lines in a text file. INPUT: Text File OUTPUT: Number of characters and number of lines. */ 1 main(int argc, char *argv[]) 2 { 3 int numChars = 0; 4 int numLines = 0; 5 char chr; 6 FILE *fp = NULL; 8 if (argc < 2) 9 { 10 printf(“\nUsage: %s <filename>”, argv[0]); 11 return (-1); 12 } 13 fp = fopen(argv[1], “r”);

Program COUNT (cont’d) 14 if (fp == NULL) 15 { 16 perror(argv[1]); /* display error message */ 17 return (-2); 18 } 19 while (!feof(fp)) 20 { 21 chr = getc(fp); /* read character */ 22 if (chr == ‘\n’) /* if carriage return */ 23 ++numLines; 24 else 25 ++numChars; 26 } 27 printf(“\nNumber of characters = %d”, numChars); 28 printf(“\nNumber of lines = %d”, numLines); 29 }

The Flowgraph for COUNT The junction at line 12 and line 18 are not needed because if you are at these lines then you must also be at line 14 and 19 respectively.

Test Cases to Satisfy Path Coverage for COUNT Complete path testing of COUNT is impossible because there are an infinite number of distinct text files that may be used as inputs to COUNT.

Test Cases to Satisfy Statement Testing Coverage for COUNT

Test Cases to Satisfy Statement Testing Coverage for COUNT

Test Cases to Satisfy Branch Testing Coverage for COUNT

Summary The object of control-flow testing is to execute enough tests to assure that statement and branch coverage has been achieved. Select paths as deviation from the normal paths. Add paths as needed to achieve coverage. Use instrumentation (manual or using tools) to verify paths. Document all tests and expected test results. A test that reveals a bug has succeeded, not failed.