https://www.lri.fr/ linaye/gl.html

Similar documents
EECS 4313 Software Engineering Testing. Topic 01: Limits and objectives of software testing Zhen Ming (Jack) Jiang

Programming Embedded Systems

Software Testing Fundamentals. Software Testing Techniques. Information Flow in Testing. Testing Objectives

Test automation / JUnit. Building automatically repeatable test suites

Test automation Test automation / JUnit

Junit Overview. By Ana I. Duncan

Test-Driven Development JUnit

EECS 4313 Software Engineering Testing

Ingegneria del Software Corso di Laurea in Informatica per il Management

Tuesday, November 15. Testing

Test-Driven Development JUnit

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013!

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

Darshan Institute of Engineering & Technology for Diploma Studies

Testing & Debugging TB-1

CS 520 Theory and Practice of Software Engineering Fall 2018

Topics in Software Testing

Software Testing. 1. Testing is the process of demonstrating that errors are not present.

Introduc)on to tes)ng with JUnit. Workshop 3

Tools for Unit Test JUnit

Introduction to JUnit

Introduction to Software Engineering

CS18000: Programming I

Agenda. JUnit JaCoCo Project. CSE 4321, Jeff Lei, UTA

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Tools for Unit Test - JUnit

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

Software Test. Levels of test. Types of test. Regression test The JUnit tool for unit testing Java programs. System test Integration test Unit test

Testing: Test design and testing process

Test automation / JUnit. Building automatically repeatable test suites

Software Testing part II (white box) Lecturer: Giuseppe Santucci

Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

JUnit Framework. Terminology: assertions, annotations, fixtures. Dr. Siobhán Drohan Mairead Meagher. Produced by:

Manuel Oriol, CHCRC-C, Software Testing ABB

1 Visible deviation from the specification or expected behavior for end-user is called: a) an error b) a fault c) a failure d) a defect e) a mistake

Section 4: Graphs and Testing. Slides by Erin Peach and Nick Carney

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

(From Glenford Myers: The Art of Software Testing)

SWE 434 Software Testing and Validation

Part 5. Verification and Validation

F. Tip and M. Weintraub FUNCTIONAL TESTING

Three General Principles of QA. COMP 4004 Fall Notes Adapted from Dr. A. Williams

CS 4387/5387 SOFTWARE V&V LECTURE 4 BLACK-BOX TESTING

Type Checking and Type Equality

Unit testing. JUnit. JUnit and Eclipse. A JUnit test class 3/6/17. A method is flagged as a JUnit test case.

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Programming Embedded Systems

An Introduction to Systematic Software Testing. Robert France CSU

Agile Software Development. Lecture 7: Software Testing

Software Testing. Lecturer: Sebastian Coope Ashton Building, Room G.18

Program Correctness and Efficiency. Chapter 2

Object Oriented Software Design - I

UNIT-4 Black Box & White Box Testing

Introduction to Software Testing Chapter 5.1 Syntax-based Testing

Unit testing. unit testing: Looking for errors in a subsystem in isolation. The basic idea: JUnit provides "assert" commands to help us write tests.

Lecture 15 Software Testing

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

UNIT-4 Black Box & White Box Testing

Good Luck! CSC207, Fall 2012: Quiz 3 Duration 25 minutes Aids allowed: none. Student Number: Lecture Section: L0101. Instructor: Horton

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends!

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Chapter 14 Software Testing Techniques

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Computer Science II (20082) Week 1: Review and Inheritance

C07: Testing and JUnit

Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt

Software Engineering Software Testing Techniques

Input Space Partitioning

Unit Testing. SWEN-261 Introduction to Software Engineering. Department of Software Engineering Rochester Institute of Technology

(CONDITIONALS_BOUNDARY)

Announcements. Testing. Announcements. Announcements

Aerospace Software Engineering

Motivating Example: Two Types of Errors (2) Test-Driven Development (TDD) with JUnit. Motivating Example: Two Types of Errors (1)

Test-Driven Development (TDD) with JUnit

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

Section 4: Graphs and Testing

Software Testing. Software Testing. in the textbook. Chapter 8. Verification and Validation. Verification and Validation: Goals

Software Engineering and Scientific Computing

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

And Parallelism. Parallelism in Prolog. OR Parallelism

Video 2.1. Arvind Bhusnurmath. Property of Penn Engineering, Arvind Bhusnurmath. SD1x-2 1

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

Equivalence Class Partitioning. Equivalence Partitioning. Definition and Example. Example set of classes

UNIT TESTING. Krysta Yousoufian CSE 331 Section April 19, With material from Marty Stepp, David Notkin, and The Pragmatic Programmer

Section 4: Graphs and Testing

Verification and Validation. Assuring that a software system meets a user s needs. Verification vs Validation. The V & V Process

Black Box Testing. EEC 521: Software Engineering. Specification-Based Testing. No Source Code. Software Testing

MTAT : Software Testing

Verification and Validation

Chapter 4 Defining Classes I

Testing Tactics. Structural Testing. Why Structural? Why Structural? Functional black box. Structural white box. Functional black box

What's that? Why? Is one "better" than the other? Terminology. Comparison. Loop testing. Some experts (e.g. Pezze & Young) call it structural testing

JUnit in EDA Introduction. 2 JUnit 4.3

What is Mutation Testing?

Static program checking and verification

11 Using JUnit with jgrasp

Fault-based testing. Automated testing and verification. J.P. Galeotti - Alessandra Gorla. slides by Gordon Fraser. Thursday, January 17, 13

MTAT : Software Testing

Objectives. Chapter 19. Verification vs. validation. Topics covered. Static and dynamic verification. The V&V process

MONIKA HEINER.

Transcription:

Software Engineering https://www.lri.fr/ linaye/gl.html lina.ye@centralesupelec.fr Sequence 3, 2017-2018 1/61 Software Engineering

Plan 1 2 3 4 5 2/61 Software Engineering

Software Testing 3/61 Software Engineering

Beizer s Test Philosophy Level 0 No difference between testing and debugging Adopted by many undergraduate CS majors get their programs to compile debug the programs with a few inputs 4/61 Software Engineering

Beizer s Test Philosophy Level 0 No difference between testing and debugging Adopted by many undergraduate CS majors get their programs to compile debug the programs with a few inputs A program s incorrect behavior (validation) cannot be distinguished from a mistake within the program (verification) Not very useful to develop reliable or safe software 4/61 Software Engineering

Beizer s Test Philosophy Level 1 The purpose of testing is to show correctness Run a collection of tests without finding failures 5/61 Software Engineering

Beizer s Test Philosophy Level 1 The purpose of testing is to show correctness Run a collection of tests without finding failures Cannot demonstrate that Is it a good software? Are the set of tests good? 5/61 Software Engineering

Beizer s Test Philosophy Level 1 The purpose of testing is to show correctness Run a collection of tests without finding failures Cannot demonstrate that Is it a good software? Are the set of tests good? How much testing remains to be done? No way to quantitatively express or evaluate the tests done 5/61 Software Engineering

Beizer s Test Philosophy Level 2 The purpose of testing is to show failures Create testing professions (test engineers) Put testers and developers into an adversarial relationship (not good for team morale) What to do if no failures are found? 6/61 Software Engineering

Beizer s Test Philosophy Level 2 The purpose of testing is to show failures Create testing professions (test engineers) Put testers and developers into an adversarial relationship (not good for team morale) What to do if no failures are found? Persistent problems: run a set of tests without failures Is our software very good? Is the testing weak? 6/61 Software Engineering

Beizer s Test Philosophy Level 3: good The purpose of testing is not to prove anything specific, but to reduce the risk of using the software Testing can show the presence of failures but not their absence. There is always some risk whenever we use software 7/61 Software Engineering

Beizer s Test Philosophy Level 3: good The purpose of testing is not to prove anything specific, but to reduce the risk of using the software Testing can show the presence of failures but not their absence. There is always some risk whenever we use software Collaborative work (positive): work together to reduce risk 7/61 Software Engineering

Beizer s Test Philosophy Level 3: good The purpose of testing is not to prove anything specific, but to reduce the risk of using the software Testing can show the presence of failures but not their absence. There is always some risk whenever we use software Collaborative work (positive): work together to reduce risk Level 3 Level 4 (mental discipline that increases quality; testers train developers) 7/61 Software Engineering

Criteria for classifying testing 1 Goal of testing: performance, security, robustness, etc. 8/61 Software Engineering

Criteria for classifying testing 1 Goal of testing: performance, security, robustness, etc. 2 Testing levels (the cycle V) Unit test Integration test Acceptance test 8/61 Software Engineering

Criteria for classifying testing 1 Goal of testing: performance, security, robustness, etc. 2 Testing levels (the cycle V) Unit test Integration test Acceptance test 3 System nature under testing: Black box: functional testing White box: structural testing 8/61 Software Engineering

Black and white box testing 9/61 Software Engineering

Functional testing (black box) Do not take into account the implementation Testing is based only on the inputs/outputs Data coverage 10/61 Software Engineering

Functional testing (black box) Do not take into account the implementation Testing is based only on the inputs/outputs Data coverage Generate test cases from the specification Pre-condition: generate inputs Post-condition: generate outputs 10/61 Software Engineering

Functional testing (black box) Do not take into account the implementation Testing is based only on the inputs/outputs Data coverage Generate test cases from the specification Pre-condition: generate inputs Post-condition: generate outputs Two common techniques Random testing: generate arbitrarily inputs Testing by partitioning input space 10/61 Software Engineering

Functional testing: example Example of triangle input: three integers a, b and c output: right-angled, isoceles, equilateral, invalid 11/61 Software Engineering

Functional testing: example Example of triangle input: three integers a, b and c output: right-angled, isoceles, equilateral, invalid Lots of test cases required right-angled triangle, isoceles triangle, equilateral triangle, invalid all permutations of two equal sides all permutations of a+b<c all permutations of a+b=c all permutations of a=b and a+b=c values in MAXINT non-integer inputs 11/61 Software Engineering

Random testing Pick possible inputs uniformly by treating all inputs as equally valuable But: defects are not distributed uniformly Assume Roots applies quadratic equation x = b ± b 2 4ac 2a, which fails if b 2 4ac = 0 and a = 0 Random sampling is unlikely to choose a=0 and b=0 Many defects are related to specific inputs Input space partitioning 12/61 Software Engineering

Input space partitioning Impossible to test all an integer of 32-bit as input 4,294,967,296 values one hour on the recent machine 3 integers of 32-bit, (2 32 ) 3 10 28 legal inputs: 2.5 billion years with 10 12 tests/s 13/61 Software Engineering

Input space partitioning Impossible to test all an integer of 32-bit as input 4,294,967,296 values one hour on the recent machine 3 integers of 32-bit, (2 32 ) 3 10 28 legal inputs: 2.5 billion years with 10 12 tests/s partition input space into equivalent classes The values in the same equivalent class have the same behaviors from the specification point of view 13/61 Software Engineering

Input space partitioning Impossible to test all an integer of 32-bit as input 4,294,967,296 values one hour on the recent machine 3 integers of 32-bit, (2 32 ) 3 10 28 legal inputs: 2.5 billion years with 10 12 tests/s partition input space into equivalent classes The values in the same equivalent class have the same behaviors from the specification point of view Test cases: for each equivalent class a value of the limit a value just before the limit a value in the middle a value just after the limit (robustness test) 13/61 Software Engineering

Partition: examples Example 1: absolute value 2 equivalent classes: value 0 and value 0 9 test cases: MinInt, MinInt+1, -10, -1, 0, 1, 5, MaxInt-1, MaxInt 14/61 Software Engineering

Partition: examples Example 1: absolute value 2 equivalent classes: value 0 and value 0 9 test cases: MinInt, MinInt+1, -10, -1, 0, 1, 5, MaxInt-1, MaxInt Example 2: insert to a list (size is 20) List level: empty list or 1 element full list 19 or 20 elements list of 10 elements (middle) 14/61 Software Engineering

Partition: examples Example 1: absolute value 2 equivalent classes: value 0 and value 0 9 test cases: MinInt, MinInt+1, -10, -1, 0, 1, 5, MaxInt-1, MaxInt Example 2: insert to a list (size is 20) List level: empty list or 1 element full list 19 or 20 elements list of 10 elements (middle) Insertion level just before and after the first element just before and after the last element in the middle of the list 14/61 Software Engineering

Structurel testing (white box) Internal structure of software as criteria to generate test cases 15/61 Software Engineering

Structurel testing (white box) Internal structure of software as criteria to generate test cases Coverage criteria Block/Instruction coverage each instruction should be covered by at least one test case Branch/Decision coverage each branch should be covered by at least one test case implies the block coverage Path coverage each execution path should be covered by at least one test case implies branch coverage 15/61 Software Engineering

Structurel testing: example Coverage of instruction blocks Coverage of branches Coverage of paths 16/61 Software Engineering

Structurel testing: example Coverage of instruction blocks 2 paths suffice Coverage of branches 3 paths required Coverage of paths 3 paths required 16/61 Software Engineering

Structurel testing: example Coverage of instruction blocks 2 paths suffice Coverage of branches 3 paths required coverage of paths 3 paths? how many iterations needed? N? 17/61 Software Engineering

Structurel testing: example Coverage of instruction blocks 2 paths suffice Coverage of branches 3 paths required coverage of paths 3 paths? how many iterations needed? N? number of paths 3 N exponential with the number of iterations 17/61 Software Engineering

Really all covered? 18/61 Software Engineering

Cyclomatic complexity A source code complexity measurement that determines the number of linearly independent path (not a sub-path of another path) It is calculated by developing a Control Flow Graph of the code Lower the Program s cyclomatic complexity, lower the risk to modify and easier to understand 19/61 Software Engineering

Cyclomatic complexity A source code complexity measurement that determines the number of linearly independent path (not a sub-path of another path) It is calculated by developing a Control Flow Graph of the code Lower the Program s cyclomatic complexity, lower the risk to modify and easier to understand Calculate cyclomatic complexity: CC = E - N + 2*P E = number of edges in the flow graph N = number of nodes in the flow graph P = number of nodes that have exit points 19/61 Software Engineering

Control flow graph The control structure of a program can be represented by the control flow graph of the program. The control flow graph G = (N, E) of a program consists of a set of nodes N and a set of edge E. 20/61 Software Engineering

Control flow graph The control structure of a program can be represented by the control flow graph of the program. The control flow graph G = (N, E) of a program consists of a set of nodes N and a set of edge E. A statement node contains a sequence of statements. The control must enter from the first statement and exit from the last statement. A decision node contains a conditional statement that creates 2 or more control branches. A merge node usually does not contain any statement and is used to represent a program point where multiple control branches merge. 20/61 Software Engineering

Control flow graph The control structure of a program can be represented by the control flow graph of the program. The control flow graph G = (N, E) of a program consists of a set of nodes N and a set of edge E. A statement node contains a sequence of statements. The control must enter from the first statement and exit from the last statement. A decision node contains a conditional statement that creates 2 or more control branches. A merge node usually does not contain any statement and is used to represent a program point where multiple control branches merge. There is an edge from node n 1 to node n 2 if the control may flow from the last statement in n1 to the first statement in n2. 20/61 Software Engineering

Example IF A == 10 THEN IF B > C THEN A = B ELSE A = C ENDIF ENDIF Print A Print B Print C 21/61 Software Engineering

Example IF A == 10 THEN IF B > C THEN A = B ELSE A = C ENDIF ENDIF Print A Print B Print C E=8; N=7; P=1 CC=E-N+ 2*P =8-7+2=3 21/61 Software Engineering

Functional vs. structural The structural approaches can find program errors more easily (verification) The functional approaches can find incorrect behaviors more easily (validation) They are complemented: missing functionality defects: functional testing decision defects: structural testing 22/61 Software Engineering

JUnit JUnit is a unit testing framework designed for the Java programming Authors: Erich Gamma, Kent Beck Objective If the test cases are easy to be created and executed, then the developers would be required to do this. 23/61 Software Engineering

JUnit 24/61 Software Engineering

Test Automation A test script to define: the actions sent to the System Under Test (SUT) the responses expected of SUT the way to determinate whether a test fails or not Test execution system read and execute the scripts on the SUT save test results 25/61 Software Engineering

What is a JUnit test A test script is just a set of Java methods The idea is to create and use the objects before verifying whether these objects have the good properties. Assertions A package containing the functions that allow the verification of different properties: equality between objects reference identity reference null/non-null The assertions are used to determinate the verdict of a test: Pass or Fail 26/61 Software Engineering

A JUnit test case /* Test of setname() method, class Value */ @Test public void createandsetname(){ Value v1=new Value(); v1.setname("y"); String expected="y"; String actual=v1.getname(); } Assert.assertEquals(expected, actual); 27/61 Software Engineering

A JUnit test case /* Test of setname() method, class Value */ @Test public void createandsetname(){ Value v1=new Value(); define this method as a test v1.setname("y"); String expected="y"; String actual=v1.getname(); } Assert.assertEquals(expected, actual); 28/61 Software Engineering

A JUnit test case /* Test of setname() method, class Value */ @Test public void createandsetname(){ Value v1=new Value(); v1.setname("y"); String expected="y"; String actual=v1.getname(); confirm that setname saves the name of v1 Assert.assertEquals(expected, actual); } 29/61 Software Engineering

A JUnit test case /* Test of setname() method, class Value */ @Test public void createandsetname(){ Value v1=new Value(); v1.setname("y"); String expected="y"; String actual=v1.getname(); Assert.assertEquals(expected, actual); } verify the name of v1 30/61 Software Engineering

A JUnit test case /* Test of setname() method, class Value */ @Test public void createandsetname(){ Value v1=new Value(); v1.setname("y"); String expected="y"; String actual=v1.getname(); } Assert.assertEquals(expected, actual); expected and actual should be the same 31/61 Software Engineering

Test verdicts A verdict is the execution result of one test. Pass: the test has been correctly executed and the software has the expected behavior. Fail: the test has been correctly executed and the software has the unexpected behavior. Error: the test has not been correctly executed, which may due to unexpected event during the test the test cannot be initialized correctly 32/61 Software Engineering

Test verdicts @Test public void testerrorvstestfailure() { String s =new String("jacob"); s=null; assertequals('j', s.charat(0) ); /*above line throws test error as you are trying to access charat() method on null reference*/ assertequals(s, "jacob")); /*above line throws Test failure as the actual value null is not equal to "jacob"*/ } 33/61 Software Engineering

Eclipse interface 34/61 Software Engineering

Eclipse interface 35/61 Software Engineering

Eclipse interface 36/61 Software Engineering

Eclipse To create a new test class from an existing class: click right on the class New JUnit Test Case To execute the set of tests use the same arrow for program execution the test result shown to the left 37/61 Software Engineering

Organization of JUnit tests Each method corresponds to a test with its own verdict (pass, error, fail). Conventionally, all tests for the same class are collected in the same test class naming convention: demo Class to be tested: NameClass Class containing tests: NameClassTest 38/61 Software Engineering

Execute JUnit tests There is no graphic interface of JUnit to run the tests, but an API is available to be used. Eclipse uses the API of JUnit to provide graphic interface to run tests. 39/61 Software Engineering

Execute JUnit tests There is no graphic interface of JUnit to run the tests, but an API is available to be used. Eclipse uses the API of JUnit to provide graphic interface to run tests. When a test class is executed, all test methods are executed. The order to execute these methods is not predefined. It is necessary to write the tests whose result is independent of the execution order. 39/61 Software Engineering

Assertions The assertions are defined in the class Assert: if an assertion is true, then the execution continues if an assertion is false, then the execution terminates and the test result is fail if any other exception is generated, the test result is error if no assertion is false in the method, the test result is pass All assertion methods are static. 40/61 Software Engineering

Assertion methods Test boolean condition (true or false) asserttrue(condition) assertfalse(condition) Test if an object is null or non-null assertnull(object) assertnotnull(object) Test if two objects are identical (i.e., two references to the same object) assertsame(expected, actual): true if expected==actual assertnotsame(expected, actual) 41/61 Software Engineering

Assertion methods Test equality between two objects assertequals(expected, actual): valid if expected.equals(actual) Test equality between two arrays assertarrayequals(expected, actual) The arrays should have the same size for all correct values of i, test according to the cases: assertequals(expected[i], actual[i]) or assertarrayequals(expected[i], actual[i]) There exists also an assertion that always fails: fail() 42/61 Software Engineering

The parameters of assertion methods If an assertion method has two parameters, the first is the expected value and the second is the actual value This has no impact on the test result but is used to send the message to users All assertion methods can have an extra parameter whose type is String, which is on the first place. This parameter will be included in the error message if the assertion fails. Examples: fail(message) assertequals(message, expected, actual) 43/61 Software Engineering

Equality assertions assertequals(a, b) is based on the method equals() of the class that is tested This assertion is to evaluate a.equals(b) Recall: if the method equals is not defined in the class, then it is inherited from the parent class Object If a and b are the primitive types like int, boolean,..., then the following behavior is implemented for assertequals(a, b): a and b with the equivalence of their object type: (Integer, Boolean,...), and then a.equals(b) is evaluated. 44/61 Software Engineering

Assertions for non-integer number When one compares the non-integer number (double or float), there is an extra parameter that is necessary: delta The assertion evaluate: Math.abs(expected-actual) delta This is done to avoid the rounding errors Example: assertequals(adouble, anotherdouble, 0.0001) 45/61 Software Engineering

Test fixture The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. The fixtures are composed of The objects and the resources used for tests The initialization (setup) and deallocation (teardown) of these objects and resources. 46/61 Software Engineering

Setup The set of tasks effectuated before each test. Example: create the interesting objects, based on which one works, open a connection network, etc... Use the key word @Before before the methods All methods with this key word will be executed before each test, but with any possible order. 47/61 Software Engineering

Teardown The set of tasks effectuated after each test. Example: be sure that the resources are liberated, reset the system in the good state for the following tests With the key word @after before the methods All methods with this key word will be executed after each test, but with any possible order. The methods are executed even when the test fails 48/61 Software Engineering

Setup and Teardown: Example public class OutputTest { private File output; @Before public void createoutputfile () { output=new file (...); } @After public void deleteoutputfile () { output.delete(); } @Test public void test1withfile () { /** code for test case objective */ } @Test public void test2withfile () { /** code for test case objective */ } } 49/61 Software Engineering

Execution order 1 createoutputfile() 2 test1withfile() 3 deleteoutputfile() 4 createoutputfile() 5 test2withfile() 6 deleteoutputfile() Remark: test1withfile can be executed after test2withfile 50/61 Software Engineering

Once-only Setup The set of tasks effectuated only one time before the set of tests Example: restart a server With the key word @BeforeClass before the methods Can be used for a static method @BeforeClass public static void anynamehere () { /** class setup code here */ } 51/61 Software Engineering

Once-only Teardown The set of tasks effectuated only one time after the set of tests Example: stop a server With the key word @AfterClass before the methods Can be used for a static method @AfterClass public static void anynamehere () { /** class cleanup code here */ } 52/61 Software Engineering

Boring test? 53/61 Software Engineering

What is mutation testing Mutation testing involves modifying a program in small ways. Such modifications model small defects that may appear during the development. Mutation testing is a form of white-box testing. estimate/improve the efficiency of test suites find out the problems in the SUT. 54/61 Software Engineering

Principles Let Prog be a program and Tests be a set of tests: Apply the mutations on the program Prog Each mutant is created by applying one mutation on Prog A set of mutants Prog 1, Prog 2,..., Prog n Run the set of tests Tests on each mutant We say that Tests kills the mutant Prog i if an error is detected If Tests kills k mutants on n The mutation coverage of Tests is calculated by k /n Tests is considered as perfect when k = n Mutation testing is totally automatic. 55/61 Software Engineering

Mutation equivalence Tests is not perfect when: (k /n) < 1 In practice: some mutants are not different from original program Such mutants are called equivalent mutations 56/61 Software Engineering

Mutation equivalence Tests is not perfect when: (k /n) < 1 In practice: some mutants are not different from original program Such mutants are called equivalent mutations int i=2; if (i>=1) { return "foo"; }... int i=2; if (i>1) { return "foo"; } 56/61 Software Engineering

Mutation types Mutation of values: modify the values of constants or of parameters Example: the bound for cycles, the initial value, etc. Mutation of decisions: modify the conditions Example: replace the comparison > by >= or <. Mutation of declarations: delete or inverse the order of code lines. Example: delete the variable incrementation in a cycle. 57/61 Software Engineering

Mutation generation Mutation of source code The mutations are effectuated by modifying the source code that is then recompiled. Mutation of assembly language The mutations are effectuated by modifying the assembly code. 58/61 Software Engineering

Mutation generation Mutation of source code The mutations are effectuated by modifying the source code that is then recompiled. Mutation of assembly language The mutations are effectuated by modifying the assembly code. Advantage of source code A great quantity of mutations can be effectuated The mutations are similar to the errors that may generated by a programmer The mutations can easily be understood Advantage of assembly code Mutation generation is quicker. 58/61 Software Engineering

PIT: mutation testing for Java PIT is a system of mutation testing for Java based on the source code. Two methods mutation coverage: measure the efficiency of the tests line coverage: a coverage of detailed code (line by line) More information: http://pitest.org/ 59/61 Software Engineering

PIT 60/61 Software Engineering

Formal methods Principles Mathematic proofs are used on the program to demonstrate that it holds some properties Difficult to be used The only method with the guarantee For some critical applications (e.g., Meteor) 61/61 Software Engineering

Formal methods Principles Mathematic proofs are used on the program to demonstrate that it holds some properties Difficult to be used The only method with the guarantee For some critical applications (e.g., Meteor) Tool examples B method Isabelle, Coq 61/61 Software Engineering