Foundations of Software Testing Chapter 7: Test Adequacy Measurement and Enhancement Using Mutation Last update: September 3, 2007 These slides are copyrighted.

Slides:



Advertisements
Similar presentations
Foundations of Software Testing Chapter 2: Test Generation: Requirements Last update: September 3, 2007 These slides are copyrighted. They are for use.
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
MUTATION TESTING. Mutation testing is a technique that focuses on measuring the adequacy (quality) of test data (or test cases). Modify a program by introducing.
Foundations of Software Testing Chapter 6: Test Adequacy Measurement and Enhancement: Control and Data flow Last update: September 3, 2007 These slides.
Unit Testing CSSE 376, Software Quality Assurance Rose-Hulman Institute of Technology March 27, 2007.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION REGRESSION TESTING Autumn 2011.
Foundations of Software Testing Chapter 1: Section 1.19 Coverage Principle and the Saturation Effect Aditya P. Mathur Purdue University Last update: August.
1 Software Testing and Quality Assurance Lecture 9 - Software Testing Techniques.
Foundations of Software Testing Chapter 6: Test Adequacy Measurement and Enhancement: Control and Data flow Last update: September 3, 2007 These slides.
Foundations of Software Testing Chapter 6: Test Adequacy Measurement and Enhancement: Control and Data flow Last update: September 3, 2007 These slides.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 16, 1999.
Coverage Principle: A Mantra for Software Testing and Reliability Aditya P. Mathur Purdue University August 28, Cadence Labs, Chelmsford Last update:August.
1 Software Testing and Quality Assurance Lecture 5 - Software Testing Techniques.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Introduction to Software Testing Chapter 5.2 Program-based Grammars Paul Ammann & Jeff Offutt
Topics in Software Dynamic White-box Testing Part 2: Data-flow Testing
Software Testing and Validation SWE 434
© SERG Dependable Software Systems (Mutation) Dependable Software Systems Topics in Mutation Testing and Program Perturbation Material drawn from [Offutt.
Coverage – “Systematic” Testing Chapter 20. Dividing the input space for failure search Testing requires selecting inputs to try on the program, but how.
Foundations of Software Testing Chapter 5: Test Selection, Minimization, and Prioritization for Regression Testing Last update: September 3, 2007 These.
Requirements-based Test Generation for Functional Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 1 W. Eric Wong Department.
Foundations of Software Testing Chapter 1: Preliminaries Last update: September 3, 2007 These slides are copyrighted. They are for use with the Foundations.
Testing Testing Techniques to Design Tests. Testing:Example Problem: Find a mode and its frequency given an ordered list (array) of with one or more integer.
Test Drivers and Stubs More Unit Testing Test Drivers and Stubs CEN 5076 Class 11 – 11/14.
Test Coverage CS-300 Fall 2005 Supreeth Venkataraman.
White-box Testing.
White Box-based Coverage Testing (© 2012 Professor W. Eric Wong, The University of Texas at Dallas) 111 W. Eric Wong Department of Computer Science The.
Foundations of Software Testing Slides based on: Draft V1.0 August 17, 2005 Test Adequacy Measurement and Enhancement: Control and Data flow Last update:
1 Program Testing (Lecture 14) Prof. R. Mall Dept. of CSE, IIT, Kharagpur.
1 Building The Ultimate Consistent Reader. 2 Introduction We’ve already built a consistent reader (cube-Vs.-point)... Except it had variables ranging.
Mutation Testing G. Rothermel. Fault-Based Testing White-box and black-box testing techniques use coverage of code or requirements as a “proxy” for designing.
Software Testing Syntax-based Testing. Syntax Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
Key Stone Problem… Key Stone Problem… Set 17 Part 2 © 2007 Herbert I. Gross next.
Week 5-6 MondayTuesdayWednesdayThursdayFriday Testing III No reading Group meetings Testing IVSection ZFR due ZFR demos Progress report due Readings out.
Condition Testing. Condition testing is a test case design method that exercises the logical conditions contained in a program module. A simple condition.
1 Software Testing and Quality Assurance Theory and Practice Chapter 6 Domain Testing.
Foundations of Software Testing Slides based on: Draft V4.0. November 19, 2006 Test Adequacy Measurement and Enhancement Using Mutation Last update: January15,
1 © 2011 Professor W. Eric Wong, The University of Texas at Dallas Requirements-based Test Generation for Functional Testing W. Eric Wong Department of.
Mutation Testing Breaking the application to test it.
Foundations of Software Testing Chapter 6: Test Adequacy Measurement and Enhancement: Control and Data flow Last updated: April 21, 2011 These slides are.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 23, 1999.
Foundations of Software Testing Chapter 5: Test Selection, Minimization, and Prioritization for Regression Testing Last update: September 3, 2007 These.
Foundations of Software Testing Chapter 7: Test Adequacy Measurement and Enhancement Using Mutation Last update: September 3, 2007 These slides are copyrighted.
Mutation Testing Laraib Zahid & Mariam Arshad. What is Mutation Testing?  Fault-based Testing: directed towards “typical” faults that could occur in.
Software Testing and Quality Assurance Syntax-Based Testing (2) 1.
Foundations of Software Testing Slides based on: Draft V1.0 August 17, 2005 Test Adequacy Measurement and Enhancement Using Mutation Last update: October.
Introduction to Software Testing (2nd edition) Chapter 5 Criteria-Based Test Design Paul Ammann & Jeff Offutt
Functional testing, Equivalence class testing
Aditya P. Mathur Purdue University
Software TestIng White box testing.
Software Testing.
Software Testing.
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Condition Testing.
Faults, Errors, Failures CS 4501 / 6501 Software Testing
Aditya P. Mathur Purdue University
Structural testing, Path Testing
CHAPTER 4 Test Design Techniques
Aditya P. Mathur Purdue University
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing (Lecture 11-a)
Introduction to Software Testing Chapter 5.2 Program-based Grammars
Aditya P. Mathur Purdue University Fall 2007
Sudipto Ghosh CS 406 Fall 99 November 16, 1999
Laboratory of Advanced Research on Software Technology
Software Testing Syntax-based Testing.
Coverage Principle: A Mantra for Software Testing and Reliability
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Mutation Testing Faults are introduced into the program by creating many versions of the program called mutants. Each mutant contains a single fault. Test.
Presentation transcript:

Foundations of Software Testing Chapter 7: Test Adequacy Measurement and Enhancement Using Mutation Last update: September 3, 2007 These slides are copyrighted. They are for use with the Foundations of Software Testing book by Aditya Mathur. Please use the slides but do not remove the copyright notice. Aditya P. Mathur Purdue University

© Aditya P. Mathur What is program mutation?  Suppose that program P has been tested against a test set T and P has not failed on any test case in T. Now suppose we do the following: Changed to PP’ What behavior do you expect from P’ against tests in T?

© Aditya P. Mathur What is program mutation? [2]  P’ is known as a mutant of P.  There might be a test t in T such that P(t)≠P’(t). In this case we say that t distinguishes P’ from P. Or, that t has killed P’.  There might not be any test t in T such that P(t)≠P’(t). In this case we say that T is unable to distinguish P and P’. Hence P’ is considered live in the test process.

© Aditya P. Mathur What is program mutation? [3]  If there does not exist any test case t in the input domain of P that distinguishes P from P’ then P’ is said to be equivalent to P.  If P’ is not equivalent to P but no test in T is able to distinguish it from P then T is considered inadequate.  A non-equivalent and live mutant offers the tester an opportunity to generate a new test case and hence enhance T.

© Aditya P. Mathur Test adequacy using mutation [1]  Given a test set T for program P that must meet requirements R, a test adequacy assessment procedure proceeds as follows.  Step 1: Create a set M of mutants of P. Let M={M 0, M 1 …M k }. Note that we have k mutants.  Step 2: For each mutant M i find if there exists a t in T such that M i (t) ≠P(t). If such a t exists then M i is considered killed and removed from further consideration.

© Aditya P. Mathur Test adequacy using mutation [2]  Step 3: At the end of Step 2 suppose that k 1 ≤ k mutants have been killed and (k-k 1 ) mutants are still live. Case 1: (k-k 1 )=0: T is adequate with respect to mutation. Case 2: (k-k 1 )>0: Enhance test set T using live mutants.

© Aditya P. Mathur Test enhancement using mutation  Step 1: A new test t is designed with the objective of distinguishing at least one of the live mutants; let us say this is mutant m.  Step 2: If t does not distinguish m then another test t needs to be designed to distinguish m. Suppose that t does distinguish m.  Step 3: It is also possible that t distinguishes other live mutants.  Step 4: Add t to T.  Repeat the enhancement process from other live mutants.

© Aditya P. Mathur Error detection using mutation  As with any test enhancement technique, there is no guarantee that tests derived to distinguish live mutants will reveal a yet undiscovered error in P. Nevertheless, empirical studies have found mutation to be the most powerful of all formal test enhancement techniques.  The next simple example illustrates how test enhancement using mutation detects errors.

© Aditya P. Mathur Error detection using mutation [2]  Consider the following function foo that is required to return the sum of two integers x and y. Clearly foo is incorrect. int foo(int x, y){ return (x-y); } This should be return (x+y);

© Aditya P. Mathur Error detection using mutation [3]  Now suppose that foo has been tested using a test set T that contains two tests: T={ t1:, t2: }  First note that foo behaves perfectly fine on each test in T, i.e., foo returns the expected value for each test case in T. Also, T is adequate with respect to all control and data flow based test adequacy criteria.

© Aditya P. Mathur Error detection using mutation [4]  Note that M1 is obtained by replacing the - operator by a + operator, M2 by replacing y by 0, and M3 by replacing x by 0. int foo(int x, y){ return (x+y); } M1: int foo(int x, y){ return (x-0); } M2: int foo(int x, y){ return (0+y); } M3: Let us evaluate the adequacy of T using mutation. Suppose that the following three mutants are generated from foo.

© Aditya P. Mathur Error detection using mutation [4] Next we execute each mutant against tests in T until the mutant is distinguished or we have exhausted all tests. Here is what we get. Test (t)foo(t)M1(t)M2(t)M3(t) t11110 t2 0 Live Killed T={ t1:, t2: }

© Aditya P. Mathur Error detection using mutation [5] Let us examine the following two live mutants. int foo(int x, y){ return (x+y); } M1: int foo(int x, y){ return (x-0); } M2: Let us focus on M1. A test that distinguishes M1 from foo must satisfy the following condition: x-y≠x+y implies y ≠0. Hence we get t3:

© Aditya P. Mathur Error detection using mutation [6] Executing foo on t3 gives us foo(t3)=0. However, according to the requirements we must get foo(t3)=2. Thus t3 distinguishes M1 from foo and also reveals the error. int foo(int x, y){ return (x+y); } M1: int foo(int x, y){ return (x-0); } M2:

© Aditya P. Mathur Guaranteed error detection Sometimes there exists a mutant P’ of program P such that any test t that distinguishes P’ from P also causes P to fail. More formally: Let P’ be a mutant of P and t a test in the input domain of P. We say that P’ is an error revealing mutant if the following condition holds for any t. P’(t) ≠P(t) and P(t) ≠R(t), where R(t) is the expected response of P based on its requirements.

© Aditya P. Mathur Distinguishing a mutant A test case t that distinguishes a mutant M from its parent program P program must satisfy the following three conditions: Condition 1: Reachability: t must cause M to follow a path that arrives at the mutated statement in M. Condition 2: Infection: If S in is the state of the mutant upon arrival at the mutant statement and S out the state soon after the execution of the mutated statement, then S in ≠ S out. Condition 3: Propagation: Difference between S in and S out must propagate to the output of M such that the output of M is different from that of P.

© Aditya P. Mathur Mutant operators A mutant operator O is a function that maps the program under test to a set of k (zero or more) mutants of P. O(P) M1 M2 Mk ….

© Aditya P. Mathur Mutant operators [2] A mutant operator creates mutants by making simple changes in the program under test. For example, the “variable replacement” mutant operator replaces a variable name by another variable declared in the program. A “relational operator replacement” mutant operator replaces relational operator with another relational operator.

© Aditya P. Mathur Mutant operators: Examples Mutant operatorIn PIn mutant Variable replacementz=x*y+1;x=x*y+1; z=x*x+1; Relational operator replacement if (x<y)if(x>y) if(x<=y) Off-by-1z=x*y+1;z=x*(y+1)+1; z=(x+1)*y+1; Replacement by 0z=x*y+1;z=0*y+1; z=0; Arithmetic operator replacement z=x*y+1;z=x*y-1; z=x+y-1;

© Aditya P. Mathur Mutants: First order and higher order A mutant obtained by making exactly “one change” is considered first order. A mutant obtained by making two changes is second order. Similarly higher order mutants can be defined. For example, a second order mutant of z=x+y; is x=z+y; where the variable replacement operator has been applied twice. In practice only first order mutants are generated for two reasons: (a) to lower the cost of testing and (b) most higher order mutants are killed by tests adequate with respect to first order mutants.

© Aditya P. Mathur A misconception There is a widespread misconception amongst testing educators, researchers, and practitioners that any “coverage” based technique, including mutation, will not be able to detect errors due to missing path. Consider the following programs. int foo(int x, y){ int p=0; if(x<y) p=p+1; return(x+p*y); } int foo(int x, y){ int p=0; if(x<y) p=p+1; else p=p-1; return(x+p*y); } Missing else Program under test Correct program

© Aditya P. Mathur A misconception [2] (a)Suggest at least one mutant M of foo that is guaranteed to reveal the error; in other words M is an error revealing mutant. (b) Suppose T is decision adequate for foo. Is T guaranteed to reveal the error? (c) Suppose T is def-use adequate for foo. Is T guaranteed to reveal the error?

© Aditya P. Mathur Summary  Mutation testing is the most powerful technique for the assessment and enhancement of tests.  Identification of equivalent mutants is an undecidable problem --similar the identification of infeasible paths in control or data flow based test assessment.  Mutation, as with any other test assessment technique, must be applied incrementally and with assistance from good tools.