+ All Categories
Home > Documents > Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation...

Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation...

Date post: 22-Jan-2021
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
131
Mutaon Analysis & Tesng CMPT 473 Soſtware Quality Assurance Nick Sumner With material from Ammann & Offu, Patrick Lam, Gordon Fraser
Transcript
Page 1: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

Mutation Analysis & Testing

CMPT 473Software Quality Assurance

Nick SumnerWith material from Ammann & Offutt, Patrick Lam, Gordon Fraser

Page 2: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

2

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

Page 3: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

3

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

Page 4: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

4

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

Requirements

Page 5: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

5

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

Requirements Tests

Page 6: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

6

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

A

G

BC

EDF

Requirements Tests

Page 7: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

7

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

A

G

BC

EDF

ABCDGACDGABCEGACEGACEFFEGEFEFEF

Requirements Tests

Page 8: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

8

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.

C1 C2

A

G

BC

EDF

ABCDGACDGABCEGACEGACEFFEGEFEFEF Tests

Requirements Tests

Page 9: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

9

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.– But they still have difficulties finding bugs!

Page 10: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

10

How Else Can We Judge Adequacy?

● Input & graph based techniques provide requirements that measure quality.– But they still have difficulties finding bugs!– Can we try to measure that directly?

How might you go about this?

Page 11: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

11

Fault Seeding

● Insert or seed representative/typical faults

Page 12: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

12

Fault Seeding

● Insert or seed representative/typical faults● Measure how many are found or killed by the test

suite

Page 13: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

13

Fault Seeding

● Insert or seed representative/typical faults● Measure how many are found or killed by the test

suite– Effectiveness = # killed / # seeded

Page 14: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

14

Fault Seeding

● Insert or seed representative/typical faults● Measure how many are found or killed by the test

suite– Effectiveness = # killed / # seeded– Directly measures bug finding ability

Page 15: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

15

Fault Seeding

● Insert or seed representative/typical faults● Measure how many are found or killed by the test

suite– Effectiveness = # killed / # seeded– Directly measures bug finding ability

● Why might this fail?

Page 16: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

16

Fault Seeding

● Insert or seed representative/typical faults● Measure how many are found or killed by the test

suite– Effectiveness = # killed / # seeded– Directly measures bug finding ability

● Why might this fail?– What are representative faults?– Are there enough faults to be meaningful?– Did you forget to remove faults afterward?

Page 17: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

17

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original

Page 18: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

18

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs

a = b + c a = b * c

Page 19: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

19

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs– A test t kills a mutant m if t produces a different outcome

on m than the original program

Page 20: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

20

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs– A test t kills a mutant m if t produces a different outcome

on m than the original program

What does this mean?

Page 21: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

21

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs– A test t kills a mutant m if t produces a different outcome

on m than the original program● Systematically generate mutants separately from

original program

Page 22: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

22

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs– A test t kills a mutant m if t produces a different outcome

on m than the original program● Systematically generate mutants separately from

original program● The goal is to:

– Mutation Analysis – Measure bug finding ability

Page 23: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

23

Mutation Analysis & Testing

● Mutant– A valid program that behaves differently than the

original– Consider small, local changes to programs– A test t kills a mutant m if t produces a different outcome

on m than the original program● Systematically generate mutants separately from

original program● The goal is to:

– Mutation Analysis – Measure bug finding ability– Mutation Testing – create a test suite that kills a

representative set of mutants

Page 24: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

24

Mutation

● What are possible mutants?int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 25: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

25

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 26: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

26

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

● Some are not generally useful:

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Why might they not be useful?

Page 27: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

27

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

● Some are not generally useful:– (Still Born) Not compilable

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 28: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

28

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

● Some are not generally useful:– (Still Born) Not compilable– (Trivial) Killed by most test cases

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 29: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

29

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

● Some are not generally useful:– (Still Born) Not compilable– (Trivial) Killed by most test cases– (Equivalent) Indistinguishable from original program

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 30: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

30

Mutation

● What are possible mutants?

● Once we have a test case that kills a mutant, the mutant itself is no longer useful.

● Some are not generally useful:– (Still Born) Not compilable– (Trivial) Killed by most test cases– (Equivalent) Indistinguishable from original program– (Redundant) Indistinguishable from other mutants

int foo(int x, int y) { if (x > 5) {return x + y;} else {return x;}}

Page 31: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

31

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

● Mimic mistakes● Encode knowledge from other techniques

Page 32: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

32

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a;

if (b < a) { minVal = b; } return minVal;}● Mimic mistakes

● Encode knowledge from other techniques

Page 33: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

33

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { minVal = b; } return minVal;}

Mutant 1: minVal = b;

● Mimic mistakes● Encode knowledge from other techniques

Page 34: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

34

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { minVal = b; } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {

● Mimic mistakes● Encode knowledge from other techniques

Page 35: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

35

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

● Mimic mistakes● Encode knowledge from other techniques

Page 36: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

36

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; BOMB(); } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

Mutant 4: BOMB();

● Mimic mistakes● Encode knowledge from other techniques

Page 37: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

37

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; BOMB(); minVal = a; } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

Mutant 4: BOMB();Mutant 5: minVal = a;

● Mimic mistakes● Encode knowledge from other techniques

Page 38: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

38

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; BOMB(); minVal = a; minVal = failOnZero(b); } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

Mutant 4: BOMB();Mutant 5: minVal = a;Mutant 6: minVal = failOnZero(b);

● Mimic mistakes● Encode knowledge from other techniques

Page 39: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

39

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; BOMB(); minVal = a; minVal = failOnZero(b); } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

Mutant 4: BOMB();Mutant 5: minVal = a;Mutant 6: minVal = failOnZero(b);

What mimicsstatement coverage?

● Mimic mistakes● Encode knowledge from other techniques

Page 40: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

40

Mutationint min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; minVal = b; if (b < a) { if (b > a) { if (b < minVal) { minVal = b; BOMB(); minVal = a; minVal = failOnZero(b); } return minVal;}

Mutant 1: minVal = b;

Mutant 2: if (b > a) {Mutant 3: if (b < minVal) {

Mutant 4: BOMB();Mutant 5: minVal = a;Mutant 6: minVal = failOnZero(b);

What mimicsinput classes?

● Mimic mistakes● Encode knowledge from other techniques

Page 41: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

41

Mutation Analysis

MutantsMutant 1Mutant 2Mutant 3Mutant 4Mutant 5Mutant 6

Page 42: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

42

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3Mutant 4Mutant 5Mutant 6

min(1,2) 1min(2,1) 1

Page 43: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

43

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3Mutant 4Mutant 5Mutant 6

min(1,2) 1min(2,1) 1

Try every mutant on test 1.

Page 44: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

44

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3Mutant 4Mutant 5Mutant 6

min(1,2) 1min(2,1) 1Ki

lled

Page 45: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

45

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3Mutant 4Mutant 5Mutant 6

min(1,2) 1min(2,1) 1Ki

lled

Try every live mutant on test 2.

Page 46: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

46

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3

min(1,2) 1Ki

lled

Mutant 4Mutant 5Mutant 6

min(2,1) 1

Kille

d

Page 47: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

47

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3

min(1,2) 1Ki

lled

Mutant 4Mutant 5Mutant 6

min(2,1) 1

Kille

d

So the mutation score is...

Page 48: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

48

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3

min(1,2) 1Ki

lled

Mutant 4Mutant 5Mutant 6

min(2,1) 1

Kille

d

So the mutation score is... 4/5. Why?

Page 49: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

49

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3

min(1,2) 1Ki

lled

Mutant 4Mutant 5Mutant 6

min(2,1) 1

Kille

d

min3(int a, int b): int minVal; minVal = a; if (b < minVal) minVal = b; return minVal;

min6(int a, int b): int minVal; minVal = a; if (b < a) minVal = failOnZero(b); return minVal;

So the mutation score is... 4/5. Why?

Page 50: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

50

Mutation Analysis

Mutants Test SuiteMutant 1Mutant 2Mutant 3

min(1,2) 1Ki

lled

Mutant 4Mutant 5Mutant 6

min(2,1) 1

Kille

d

min3(int a, int b): int minVal; minVal = a; if (b < minVal) minVal = b; return minVal;

min3(int a, int b): int minVal; minVal = a; if (b < a) minVal = failOnZero(b); return minVal;

Equivalent to the original!There is no injected bug.

So the mutation score is... 4/5. Why?

Page 51: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

51

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

Page 52: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

52

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

# Killed#Mutants−#Equivalent

Page 53: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

53

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

# Killed#Mutants−#Equivalent

Page 54: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

54

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation

# Killed#Mutants−#Equivalent

Page 55: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

55

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation

# Killed#Mutants−#Equivalent

Page 56: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

56

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation

# Killed#Mutants−#Equivalent

Page 57: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

57

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation

# Killed#Mutants−#Equivalent

Page 58: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

58

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation?

# Killed#Mutants−#Equivalent

Page 59: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

59

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation?

# Killed#Mutants−#Equivalent

Page 60: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

60

Equivalent Mutants

● Equivalent mutants are not bugs and should not be counted

● New Mutation Score:

● Detecting equivalent mutants is undecidable in general

● So why are they equivalent?

Reachability Infection Propagation? ?

More on this later....

# Killed#Mutants−#Equivalent

Page 61: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

61

Equivalent Mutants

● Identifying equivalent mutants is one of the most expensive / burdensome aspects of mutation analysis.

Page 62: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

62

Equivalent Mutants

● Identifying equivalent mutants is one of the most expensive / burdensome aspects of mutation analysis.

min3(int a, int b): int minVal; minVal = a; if (b < minVal) minVal = b; return minVal;

Requires reasoning about whythe result was the same.

Page 63: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

63

Mutation Testing

● Given an unkilled mutant, how can we improve the test suite?

Page 64: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

64

Mutation Testing

● Given an unkilled mutant, how can we improve the test suite?

min3(int a, int b): int minVal; minVal = a; if (b < a) minVal = failOnZero(b); return minVal;

Page 65: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

65

Mutation Testing

● Given an unkilled mutant, how can we improve the test suite?

min3(int a, int b): int minVal; minVal = a; if (b < a) minVal = failOnZero(b); return minVal;

min(2,0) 0New Test:New Score: 5/5

Page 66: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

66

Mutation Operators

● The mutants should guide the tester toward an effective test suite

Page 67: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

67

Mutation Operators

● The mutants should guide the tester toward an effective test suite– Need a 'representative' pool of mutants

idea: “If there is a fault, there is a mutant to match it”

Page 68: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

68

Mutation Operators

● The mutants should guide the tester toward an effective test suite– Need a 'representative' pool of mutants

idea: “If there is a fault, there is a mutant to match it”– Need a rigorous way of creating mutants

Page 69: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

69

Mutation Operators

● The mutants should guide the tester toward an effective test suite– Need a 'representative' pool of mutants

idea: “If there is a fault, there is a mutant to match it”– Need a rigorous way of creating mutants

● Mutation Operators– Systematic changes that may be applied to produce

mutants

Page 70: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

70

Mutation Operators

● The mutants should guide the tester toward an effective test suite– Need a 'representative' pool of mutants

idea: “If there is a fault, there is a mutant to match it”– Need a rigorous way of creating mutants

● Mutation Operators– Systematic changes that may be applied to produce

mutants– Language dependent, but often similar

Page 71: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

71

Mutation Operators

● The mutants should guide the tester toward an effective test suite– Need a 'representative' pool of mutants

idea: “If there is a fault, there is a mutant to match it”– Need a rigorous way of creating mutants

● Mutation Operators– Systematic changes that may be applied to produce

mutants– Language dependent, but often similar

Why might they be language dependent?

Page 72: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

72

Some Mutation Operators – in Java

● Absolute Value Insertion– Each arithmetic (sub)expression is wrapped with abs(),

-abs(), and failOnZero()

w = x + y + z

Just for abs()?

Page 73: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

73

Some Mutation Operators – in Java

● Absolute Value Insertion– Each arithmetic (sub)expression is wrapped with abs(),

-abs(), and failOnZero()

w = x + y + z

Just for abs()?

w = abs(x) + y + z

w = x + abs(y) + z

w = x + y + abs(z)

w = abs(x + y) + z

w = x + abs(y + z)

w = abs(x + y + z)

Just for abs()!

Page 74: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

74

Some Mutation Operators – in Java

● Absolute Value Insertion– Each arithmetic (sub)expression is wrapped with abs(),

-abs(), and failOnZero()● Arithmetic Operator Replacement

– Each operator (+,-,*,/,%,...) is replaced with each other operator and LEFTOP and RIGHTOP (returning the named operand).

w = x + y + z

Page 75: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

75

Some Mutation Operators – in Java

● Absolute Value Insertion– Each arithmetic (sub)expression is wrapped with abs(),

-abs(), and failOnZero()● Arithmetic Operator Replacement

– Each operator (+,-,*,/,%,...) is replaced with each other operator and LEFTOP and RIGHTOP(returning the named operand).

w = x + y + z

w = x + y * z w = x + y ...

Page 76: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

76

Some Mutation Operators – in Java

● Absolute Value Insertion– Each arithmetic (sub)expression is wrapped with abs(),

-abs(), and failOnZero()● Arithmetic Operator Replacement

– Each operator (+,-,*,/,%,...) is replaced with each other operator and LEFTOP and RIGHTOP(returning the named operand).

● Relational Operator Replacement– Each operator (=,!=,<,<=,>,>=) is replaced with each

other and TRUEOP and FALSEOP

Page 77: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

77

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP

Page 78: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

78

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP

Could these be used to mimic edge coverage?

Page 79: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

79

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP● The operator replacement pattern continues...

– Assignment, Unary Insertion, Unary Deletion

Page 80: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

80

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP● The operator replacement pattern continues...

– Assignment, Unary Insertion, Unary Deletion● Scalar Variable Replacement

– Replace each variable use with another compatible variable in scope

What does compatible mean? Is it necessary?

Page 81: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

81

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP● The operator replacement pattern continues...

– Assignment, Unary Insertion, Unary Deletion● Scalar Variable Replacement

– Replace each variable use with another compatible variable in scope

● Bomb Statement Replacement– Replace a statement with BOMB()

Page 82: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

82

Some Mutation Operators – in Java

● Conditional Operator Replacement– Replace operators (&&, ||, &, |, ^) with each other and

LEFTOP, RIGHTOP, TRUEOP, FALSEOP● The operator replacement pattern continues...

– Assignment, Unary Insertion, Unary Deletion● Scalar Variable Replacement

– Replace each variable use with another compatible variable in scope

● Bomb Statement Replacement– Replace a statement with BOMB()

How does the BOMB() operatormimic statement coverage?

Page 83: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

83

Some Mutation Operators – in Java

● These are all intraprocedural (within one method)● What might interprocedural operators be?

Page 84: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

84

Some Mutation Operators – in Java

● These are all intraprocedural (within one method)● What might interprocedural operators be?

– Changing parameter values– Changing the call target– Changing incoming dependencies– ...

Page 85: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

85

Some Mutation Operators – in Java

● These are all intraprocedural (within one method)● What might interprocedural operators be?

– Changing parameter values– Changing the call target– Changing incoming dependencies– …

● And more...– Interface Mutation, Object Oriented Mutation, …

Page 86: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

86

Some Mutation Operators – in Java

● These are all intraprocedural (within one method)● What might interprocedural operators be?

– Changing parameter values– Changing the call target– Changing incoming dependencies– …

● And more...● Often just the simplest are used

Page 87: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

87

Mutation Operators

● Are the mutants representative of all bugs?● Do we expect the mutation score to be meaningful?

Ideas? Why? Why not?

Page 88: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

88

Mutation Operators

● Are the mutants representative of all bugs?● Do we expect the mutation score to be meaningful?

2 Key ideas are missing....

Ideas? Why? Why not?

Page 89: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

89

Competent Programmer Hypothesis

Programmers tend to write code that is almost correct

Page 90: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

90

Competent Programmer Hypothesis

Programmers tend to write code that is almost correct– So most of the time simple mutations should reflect the

real bugs.

Page 91: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

91

Coupling Effect

Tests that cover so much behavior that even simple errors are detected should also be sensitive enough to detect more complex errors

Page 92: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

92

Coupling Effect

Tests that cover so much behavior that even simple errors are detected should also be sensitive enough to detect more complex errors

– By casting a fine enough net, we'll catch the big fish, too (sorry dolphins)

Page 93: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

93

Higher Order Mutants?

Suppose traditional mutations are too simple● How could mutants be made that are more

realistic?

Page 94: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

94

Higher Order Mutants?

Suppose traditional mutations are too simple● How could mutants be made that are more

realistic?● Combine apply multiple mutation operators...

What will this do?

Page 95: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

95

Higher Order Mutants?

Suppose traditional mutations are too simple● How could mutants be made that are more

realistic?● Combine apply multiple mutation operators...● Carefully. Want to catch subtle interactions.

Page 96: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

96

Higher Order Mutants?

Suppose traditional mutations are too simple● How could mutants be made that are more

realistic?● Combine apply multiple mutation operators...● Carefully. Want to catch subtle interactions.● Still an emerging area.

Page 97: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

97

What Problems Remain?

● Scale (there are a lot of tests)

Page 98: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

98

What Problems Remain?

● Scale (there are a lot of tests)● Equivalence

Page 99: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

99

What Problems Remain?

● Scale (there are a lot of tests)● Equivalence

● Scale may be attacked in many ways

Ideas?

Page 100: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

100

What Problems Remain?

● Scale (there are a lot of tests)● Equivalence

● Scale may be attacked in many ways– Coverage filters– Short circuiting tests– Testing mutants simultaneously

Page 101: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

101

What Problems Remain?

● Scale (there are a lot of tests)● Equivalence

● Scale may be attacked in many ways– Coverage filters– Short circuiting tests– Testing mutants simultaneously

● Can also modify mutation criteria to help with both...

Page 102: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

102

Mutation Criteria

● Recall: If a test can detect a mutant, that mutant is killed by the test.

Page 103: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

103

Mutation Criteria

● Recall: If a test can detect a mutant, that mutant is killed by the test.

What does it mean if a mutant was killed?

Page 104: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

104

Mutation Criteria

● Recall: If a test can detect a mutant, that mutant is killed by the test.

What does it mean if a mutant was killed?

What does it mean if a mutant was not killed?

Page 105: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

105

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)

Page 106: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

106

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)

Reachability Infection Propagation

Page 107: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

107

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

Page 108: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

108

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

Reachability Infection Propagation?

Page 109: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

109

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but might not propagate.

How might this happen?

Page 110: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

110

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but might not propagate.

Mutation Criteria

How might this happen?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

Page 111: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

111

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How might this happen?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 10, b = 5

Page 112: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

112

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How might this happen?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 10, b = 5

minVal = 5

Page 113: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

113

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How might this happen?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 10, b = 5

minVal = 5

minVal = 5

Page 114: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

114

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How might this happen?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 10, b = 5

minVal = 5

minVal = 5

return 5

Page 115: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

115

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How can we strongly kill the mutant instead?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

Page 116: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

116

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How can we strongly kill the mutant instead?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 5, b = 10

Page 117: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

117

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How can we strongly kill the mutant instead?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 5, b = 10

minVal = 10

Page 118: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

118

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

How can we strongly kill the mutant instead?

int min(int a, int b) { int minVal; minVal = b; // was a if (b < a) { minVal = b; } return minVal;}

a = 5, b = 10

minVal = 10

return 10

Page 119: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

119

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but might not propagate.

What might an equivalent mutant look like?

int min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

Page 120: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

120

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

What might an equivalent mutant look like?

int min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; if (b < minVal) { minVal = b; } return minVal;}

Page 121: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

121

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but doesn't propagate.

They always behave the same way!

int min(int a, int b) { int minVal; minVal = a; if (b < a) { minVal = b; } return minVal;}

int min(int a, int b) { int minVal; minVal = a; if (b < minVal) { minVal = b; } return minVal;}

Page 122: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

122

Mutation Criteria

● Strongly Killed– A test strongly kills a mutant m if m(t) produces different

output than p(t)● Weakly Killed

– A test weakly kills a mutant m if m(t) produces different internal state than p(t)

– Reachable, infects, but might not propagate.Leading to...

Page 123: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

123

Mutation Criteria

● Strong Mutation Coverage– For each mutant, the test suite contains a test that

strongly kills the mutant

Page 124: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

124

Mutation Criteria

● Strong Mutation Coverage– For each mutant, the test suite contains a test that

strongly kills the mutant● Weak Mutation Coverage

– For each mutant, the test suite contains a test that weakly kills the mutant

Page 125: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

125

Mutation Criteria

● Strong Mutation Coverage– For each mutant, the test suite contains a test that

strongly kills the mutant● Weak Mutation Coverage

– For each mutant, the test suite contains a test that weakly kills the mutant

How might weak coverage help with equivalence?

Page 126: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

126

Mutation Criteria

● Strong Mutation Coverage– For each mutant, the test suite contains a test that

strongly kills the mutant● Weak Mutation Coverage

– For each mutant, the test suite contains a test that weakly kills the mutant

How might weak coverage help with equivalence?

How might weak coverage help with scalability?

Page 127: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

127

Mutation Criteria

● Strong Mutation Coverage– For each mutant, the test suite contains a test that

strongly kills the mutant● Weak Mutation Coverage

– For each mutant, the test suite contains a test that weakly kills the mutant

How might weak coverage help with equivalence?

How might weak coverage help with scalability?

Is there any reason to prefer strong coverage?

Page 128: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

128

Mutation Testing

● Considered one of the strongest criteria

Why?

Page 129: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

129

Mutation Testing

● Considered one of the strongest criteria– Mimics some input specifications– Mimics some graph coverage (node, edge, …)

Page 130: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

130

Mutation Testing

● Considered one of the strongest criteria– Mimics some input specifications– Mimics some graph coverage (node, edge, …)

● Massive number of criteria.

Why?

Page 131: Mutation Analysis & Testingwsumner/teaching/473/07-mutation.pdf · 2016. 2. 18. · 23 Mutation Analysis & Testing Mutant – A valid program that behaves differently than the original

131

Mutation Testing

● Considered one of the strongest criteria– Mimics some input specifications– Mimics some graph coverage (node, edge, …)

● Massive number of criteria.● Still not always the most tests.

Why?


Recommended