COSC 4506/ITEC 3506 Software Engineering

Slides:



Advertisements
Similar presentations
Lecture 8: Testing, Verification and Validation
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Ch6: Software Verification. 1 White-box testing  Structural testing:  (In)adequacy criteria  Control flow coverage criteria.
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.
Testing an individual module
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.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 19Slide 1 Verification and Validation l Assuring that a software system meets a user's.
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
CMSC 345 Fall 2000 Unit Testing. The testing process.
CS4311 Spring 2011 Unit Testing Dr. Guoqiang Hu Department of Computer Science UTEP.
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.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Software Testing. Software testing is the execution of software with test data from the problem domain. Software testing is the execution of software.
Software Verification Graph Model. 2 Graph Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
White Box Testing Arun Lakhotia University of Southwestern Louisiana P.O. Box Lafayette, LA 70504, USA
Theory and Practice of Software Testing
Dynamic Testing.
1 Phase Testing. Janice Regan, For each group of units Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
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 Lecture 6 Part 1: Control-flow Testing.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Software Testing. SE, Testing, Hans van Vliet, © Nasty question  Suppose you are being asked to lead the team to test the software that controls.
1 Software Testing. 2 What is Software Testing ? Testing is a verification and validation activity that is performed by executing program code.
Testing Integral part of the software development process.
Lab 7 Control-Flow Testing
PREPARED BY G.VIJAYA KUMAR ASST.PROFESSOR
Software Testing.
Testing Tutorial 7.
Software Testing.
Software Testing.
Control Flow Testing Handouts
John D. McGregor Session 9 Testing Vocabulary
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
Chapter 9, Testing.
Software Engineering (CSI 321)
Chapter 8 – Software Testing
Outline of the Chapter Basic Idea Outline of Control Flow Testing
Chapter 13 & 14 Software Testing Strategies and Techniques
Structural testing, Path Testing
White-Box Testing Techniques
Types of Testing Visit to more Learning Resources.
White-Box Testing.
UNIT-IV ECS-602 Software engineering PART-I
UNIT-4 BLACKBOX AND WHITEBOX TESTING
John D. McGregor Session 9 Testing Vocabulary
Introduction to Software Testing
Software Testing (Lecture 11-a)
White-Box Testing.
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.
White-Box Testing Techniques I
CSE403 Software Engineering Autumn 2000 More Testing
Regression Testing.
Tata Consultancy Services
UNIT-4 BLACKBOX AND WHITEBOX TESTING
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:

COSC 4506/ITEC 3506 Software Engineering Classic Testing (I)

Outline What is testing White box testing Black box testing

What is Software Testing? Several definitions: “Testing is the process of establishing confidence that a program or system does what it is supposed to.” by Hetzel 1973 “Testing is the process of executing a program or system with the intent of finding errors.” by Myers 1979 “Testing is any activity aimed at evaluating an attribute or capability of a program or system and determining that it meets its required results.” by Hetzel 1983

Testing Objectives The Major Objectives of Software Testing: - Uncover as many as errors (or bugs) as possible in a given timeline. - Demonstrate a given software product matching its requirement specifications. - Validate the quality of a software testing using the minimum cost and efforts. - Generate high quality test cases, perform effective tests, and issue correct and helpful problem reports. - What will be a good test?

What is Software Testing? Validation: Are we building the right system? How? Verification: Are we building the system right ?

What is Software Testing? Because it not only includes “narrow testing”, it is also called “Verification” testing, math proofs, informal reasoning Two fundamental approaches to verification Testing (Execution-based) experimenting with the behaviour of the product to see whether the product performs as expected dynamic process Analysis (Non-execution based) analysing the product or design document static process

Software Errors What is a software error? One common definition of a software error is a mismatch between the program and its specification. Failure/Fault/Error How many kinds?

Test Cases What is a test case (different from that in Test-Driven Approach)? A particular choice of input data to be used in testing a program A significant test case is a test case that has a high potential to uncover the presence of an error What is a test? A collection of test cases

Testing Techniques Dynamic Testing Testing in the small testing of individual module Testing in the large address the issue of decomposing and organizing the testing activity according to the modular structure of complex program

Testing in the small Two approaches in testing in the small black box testing (functional testing) operate s/w without relying on any knowledge of the way it has been designed and coded test what the program is supposed to do specification-based testing White box testing (Glass Box testing, structural coverage testing) use info about the internal structure test what the program does implementation-based testing

Control Flow Testing Data Flow Testing White box testing Control Flow Testing Data 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 selecting a set of test paths through the program. 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. 1 2 3 4 5 6 7

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); 1 2 3 4 5 6 7

Paths A path through a program is a sequence of statements that starts at an entry, junction, or decision and ends at another (possible the same), junction, decision, or exit. The length of a path is the number of links in a path. An entry/exit path or a complete path is a path that starts at a routine’s entry and ends at the same routine’s exit. 1 2 3 4 5 6 7

Path Selection Criteria There are many paths between the entry and exit points of a typical routine. Even a small routine can have a large number of paths. Independent path Any path through the program that introduce at least one new set of processing statements or a new condition Example

Path Selection Criteria loop < 20x There are 520=1014 (approx.) possible independent paths! If-then-else

Control-flow Testing Criteria We have explored 3-4 testing criteria from an infinite set of strategies: 1) Path Testing ( ): 100% path coverage. Execute all possible control flow paths through the program.

Control-flow Testing Criteria (Cont’d) 2) Statement Testing ( ): 100% statement coverage. Execute all statements in a program at least once under some test. 3) Branch Testing ( ): 100% branch coverage. Execute enough tests to assure that every branch alternative has been exercised at least once under some test.

Control-flow Testing Criteria (Cont’d) 4) Condition Testing ( ): 100% branch coverage + all possible values of the constituents of compound conditions are exercised at least once.

Statement-coverage criterion Select a test set T such that every elementary statement in P is executed at least once by some d in T based on observation: an error can not be discovered if the parts of the program containing the error are not executed elementary statement: assignments, I/O statements, procedure calls an input datum executes many statements  try to minimize the number of test cases still preserving the desired coverage

Example – Statement Coverage read (x); read (y); if x > 0 then write ("1"); else write ("2"); end if; if y > 0 then write ("3"); write ("4");   {<x = 2, y = 3>, <x = - 13, y = 51>, <x = 97, y = 17>, <x = - 1, y = - 1>} covers all statements {<x = - 13, y = 51>, <x = 2, y = - 3>} is minimal

Weakness of the criterion if x < 0 then x := -x; end if; z := x; {<x=-3} covers all statements it does not exercise the case when x is positive and the then branch is not entered What will be the test cases for Branch-coverage?

Edge (branch)-coverage criterion Select a test set T such that every edge (branch) of the control flow is exercised at least once by some d in T

Example of P1 and P2 Coverage 10 3 4 5 6 2 9 8 7 1 m a b c d e i h g f j k l T F

Weakness found := false; counter := 1; while (not found) and counter < number_of_items loop if table (counter) = desired_element then found := true; end if; counter := counter + 1; end loop; if found then write ("the desired element is in the table"); else write ("the desired element is not in the table");   test cases: (1) empty table, (2) table with 3 items, second of which is the item to look for do not discover error (< instead of ≤ )

Condition-coverage criterion Select a test set T such that every edge of P’s control flow is traversed and all possible values of the constituents of compound conditions are exercised at least once it is finer than branch (edge) coverage

Weakness of Condition-Coverage   if x ≠ 0 then y := 5; else z := z - x; end if; if z > 1 then z := z / x; z := 0; {<x = 0, z = 1>, <x = 1, z = 3>} causes the execution of all branches, but fails to expose the risk of a division by zero

Effectiveness of Control-flow Testing Studies show that control-flow testing catches 50-60% of all bugs caught during unit testing. About 33% of all bugs. Unit testing is dominated by control-flow testing methods. Statement and branch testing dominates control-flow testing. Control-flow testing is more effective for unstructured code than for code that follows structured programming.

Limitations of Control-flow Testing Control-flow testing as a sole testing technique is limited: Interface mismatches and mistakes are not caught. Not all initialization mistakes are caught by control-flow testing. Specification mistakes are not caught. Syntactically indicated behaviors (statements, edges, etc.) are often impossible unreachable code, infeasible edges, paths, etc. Adequacy criteria may be impossible to satisfy manual justification for omitting each impossible test case adequacy “scores” based on coverage example: 95% statement coverage

Test Outcomes The outcome of test is what we expect to happen as a result of the test. Test outcomes include anything we can observe in the computer’s memory that should have (not) changed as a result of the test. Since we are not “kiddie testing” we must predict the outcome of the test as part of the test design process.

Testing Process run the test observe the actual outcome compare the actual outcome to the expected outcome.

Questions About Test Outcomes Question: If the predicted and actual outcomes match, can we say that the test has been passed? Answer:? No! The desired outcome could have been achieved for the wrong reason. (coincidental correctness)

Questions About Test Outcomes Question: Assume that we ran a covering set of tests and achieved the desired outcomes for each case. Can we say that we’ve covered all branches? Answer: No! The desired outcome could have been reached by the wrong path! Path instrumentation is necessary to confirm that the outcome was achieved by the intended path.

Path Instrumentation All instrumentation methods are a variation on a theme of an interpretive trace. An interpretive trace program executes every statement in order and records: the intermediate values of all calculations the statement labels traversed ...

Path Instrumentation (Cont’d) If we run the tested routine under a trace, then we have all the information we need to confirm: the outcome of the test whether the outcome was achieved by the intended path.

Of Control-flow Testing 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 Complete path testing of ABS is theoretically possible but not practical. 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 PATHS PROCESS LINKS TEST CASES   a b c d INPUT OUTPUT abc  A Negative Integer, x -x adc A Positive Integer, x x

Test Cases to Satisfy Branch Testing Coverage for ABS PATHS DECISIONS TEST CASES   INPUT OUTPUT abc T A Negative Integer, x -x adc F A Positive Integer, x x

Example: Using Control-flow Testing to Test Program COUNT Consider the following program: /* 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; 7                 

Program COUNT (Cont’d) 8                  if (argc < 2) 9                  { 10              printf(“\nUsage: %s <filename>”, argv[0]); 11              return (-1); 12              } 13              fp = fopen(argv[1], “r”); 14              if (fp == NULL) 15              { 16              perror(argv[1]); /* display error message */ 17              return (-2); 18              }

Program COUNT (Cont’d) 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 PATHS PROCESS LINKS TEST CASES   a b c d e f g h i j k l INPUT OUTPUT ab  None “Usage: COUNT <filename>” agc Invalid Input Filename Error Message aghdjkli Input File with one character and no Carriage Return at the end of the line Number of characters = 1 Number of lines = 0 aghdefli Input file with no characters and one carriage return Number of characters = 0 Number of lines = 1  

Test Cases to Satisfy Branch Testing Coverage for COUNT   PATHS DECISIONS TEST CASES   8 14 19 22 INPUT OUTPUT ab T None “Usage: COUNT <filename>” agc F Invalid Input Filename Error Message aghdjkli T,F Input File with one character and no Carriage Return at the end of the line Number of characters = 1 Number of lines = 0 aghdefli Input file with no characters and one carriage return Number of characters = 0 Number of lines = 1  

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.