SlideShare a Scribd company logo
1 of 59
Download to read offline
PIT: state of the art of mutation testing system
Revised edition
MUTANTS KILLER
by Tàrin Gamberìni - CC BY-NC-SA 4.0
Lavora da sempre con tecnologie
Java-based free e Open Source
presso la Regione Emilia-Romagna
Si interessa di Object Oriented Design,
Design Patterns, Build Automation,
Testing e Continuous Integration
TÀRIN GAMBERÌNI
Partecipa attivamente
al Java User Group
Padova
Unit Testing
Test-Driven
Development (TDD)
Continuous Integration
Code Coverage
Mutation Testing
DEVELOPMENT
UNIT TESTING & TDD
The proof of working code
Refactor with confidence (regression)
Improve code design
Living documentation
TDD extremely valuable in some context
CONTINUOUS INTEGRATION
Maintain a single source repository
Automate the build
Cheap statics for code quality
Automate unit & integration tests
Catch problems fast
LINE COVERAGE
Is a measure of tested source code
line, statement, branch, … , coverage
LINE COVERAGE 100%
Only able to identify not tested code
Doesn't check tests are able to detect faults
Measures only which code is executed by tests
WEAK TESTS
public static String foo( boolean b ) {
if ( b ) {
performVitallyImportantBusinessFunction();
return "OK";
}
return "FAIL";
}
@Test
public void shouldFailWhenGivenFalse() {
assertEquals("FAIL", foo( false ));
}
@Test
public void shouldBeOkWhenGivenTrue() {
assertEquals("OK", foo( true ));
}
The untested side effect
WEAK TESTS
public static String foo( boolean b ) {
if ( b ) {
performVitallyImportantBusinessFunction();
return "OK";
}
return "FAIL";
}
@Test
public void shouldFailWhenGivenFalse() {
assertEquals("FAIL", foo( false ));
}
@Test
public void shouldBeOkWhenGivenTrue() {
assertEquals("OK", foo( true ));
}
The untested side effect
WEAK TESTS
public static String foo( int i ) {
if ( i >= 0 ) {
return "foo";
} else {
return "bar";
}
}
@Test
public void shouldReturnFooWhenGiven1() {
assertEquals("foo", foo( 1 ));
}
@Test
public void shouldReturnBarWhenGivenMinus1() {
assertEquals("bar", foo( -1 ));
}
The missing boundary test
WEAK TESTS
public static String foo( int i ) {
if ( i >= 0 ) {
return "foo";
} else {
return "bar";
}
}
@Test
public void shouldReturnBarWhenGiven1() {
assertEquals("bar", foo( 1 ));
}
@Test
public void shouldReturnFooWhenGivenZero() {
assertEquals("foo", foo( 0 ));
}
@Test
public void shouldReturnFooWhenGivenMinus1() {
assertEquals("foo", foo( -1 ));
}
The missing boundary test
WEAK TESTS
public static String foo(Collaborator c, boolean b) {
if ( b ) {
return c.performAction();
}
return "FOO";
} @Test
public void shouldPerformActionWhenGivenTrue() {
foo(mockCollaborator,true);
verify(mockCollaborator).performAction();
}
@Test
public void shouldNotPerformActionWhenGivenFalse() {
foo(mockCollaborator,false);
verify(never(),mockCollaborator).performAction();
}
The myopic mockist
WEAK TESTS
public static String foo(Collaborator c, boolean b) {
if ( b ) {
return c.performAction();
}
return "FOO";
} @Test
public void shouldPerformActionWhenGivenTrue() {
String result = foo(mockCollaborator,true);
verify(mockCollaborator).performAction();
assertEquals("MOCK", result);
}
@Test
public void shouldNotPerformActionWhenGivenFalse() {
String result = foo(mockCollaborator,false);
verify(never(),mockCollaborator).performAction();
assertEquals("FOO", result);
}
The myopic mockist
WHO TESTS THE TESTS ?
MUTATION TESTING
●
originally proposed by Richard Lipton
as a student in 1971
●
1st implementation tool was a PhD
work in 1980
●
recent availability of higher computing
power has led to a resurgence
●
expose weaknesses in tests (quality)
MUTATION TESTING
●
originally proposed by Richard Lipton
as a student in 1971
●
1st implementation tool was a PhD
work in 1980
●
recent availability of higher computing
power has led to a resurgence
●
expose weaknesses in tests (quality)
MUTATION
Is a small change in your program
original mutated
MUTANT
A
mutated
version of
your
program
MUTATION TESTING
generate lots of
mutants
run all tests against all mutants
check mutants:
killed or lived?
MUTANT KILLED
Proof of detected mutated code
Test is testing source code properly
If the unit test fails
MUTANT LIVED
Proof of not detected mutated code
If the unit test succeed
Test isn't testing source code
PIT: BASIC CONCEPTS
Applies a configurable set of mutators
Generates reports with test results
Manipulates the byte code generated
by compiling your code
PIT: MUTATORS
Conditionals Boundary
< → <=
<= → <
> → >=
>= → >
PIT: MUTATORS
Negate Conditionals
== → !=
!= → ==
<= → >
>= → <
< → >=
> → <=
PIT: MUTATORS
Math Mutator
+ → -
- → +
* → /
/ → *
% → *
& → |
| → &
^ → &
<< → >>
>> → <<
>>> → <<
PIT: MUTATORS
Remove Conditionals
if (a == b) {
// do something
}
if (true) {
// do something
}
→
PIT: MUTATORS
Return Values Mutator Conditionals
public Object foo() {
return new Object();
}
public Object foo() {
new Object();
return null;
}
→
PIT: MUTATORS
Void Method Call Mutator
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void
doSomething(int i) {
// does something
}
→
public int foo() {
int i = 5;
return i;
}
public void
doSomething(int i) {
// does something
}
PIT: MUTATORS
Many others
Activated by default
Conditionals Boundary Mutator - Increments Mutator -
Invert Negatives Mutator - Math Mutator - Negate
Conditionals Mutator - Return Values Mutator - Void
Method Calls Mutator
Deactivated by default
Constructor Calls Mutator - Inline Constant Mutator - Non
Void Method Calls Mutator - Remove Conditionals Mutator
- Experimental Member Variable Mutator - Experimental
Switch Mutator
PIT: MUTATORS
Application field
Traditional and class
PIT is suitable for "ordinary" java programs because
mutators change "ordinary" java language instructions.
The right mutator for the right application field
Not the best option if you are interesting testing:
●
Aspect Java programs, try AjMutator
●
Concurrent programs, try ExMan
●
Mutators for: reflection, java annotations, generics, … ?
HOW PIT WORKS
Running the tests
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
Your program
HOW PIT WORKS
Running the tests
PIT runs traditional line coverage analysis
HOW PIT WORKS
Running the tests
Generates mutant by applaying mutators
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
mutant 2
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
mutant 1
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
mutant 3
HOW PIT WORKS
Brute force
x = 9
100 tests x 1.2ms = 0.12s
0.12s x 10000 mutants = 20min !!!
1000 class x 10 mutants per class = 10000 mutants
HOW PIT WORKS
Running the tests
PIT leverages line coverage to discard tests
that do not exercise the mutated line of code
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
public int foo() {
int i = 5;
doSomething(i);
return i;
}
public void doSomething(int i) {
// does something
}
mutant 3
HOW PIT WORKS
Extremely fast
x = 1
x = 1
x = 2 4 < 9
HOW PIT WORKS
Outcomes
● Killed, Lived
● No coverage: the same as Lived except there were no
tests that exercised the mutated line of code
● Non viable: bytecode was in some way invalid
● Timed Out: infinite loop
● Memory error: mutation that increases the amount of
memory used
● Run error: a large number of run errors probably
means something went wrong
PIT ECOSYSTEM
Tools
Command line
Other IDEs as a
Java application
( )
EXAMPLE
class Ticket
EXAMPLE
testGetPrice_withAge11
EXAMPLE
testGetPrice_withAge71
EXAMPLE
testGetPrice_withAge18
EXAMPLE
mvn org.pitest:pitest-maven:mutationCoverage
>> Generated 8 mutations Killed 6 (75%)
>> Ran 11 tests (1.38 tests per mutation)
=================================================================
- Mutators
=================================================================
> org.pitest...ConditionalsBoundaryMutator
>> Generated 2 Killed 0 (0%)
> KILLED 0 SURVIVED 2 TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
-----------------------------------------------------------------
> org.pitest...ReturnValsMutator
>> Generated 3 Killed 3 (100%)
> KILLED 3 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
EXAMPLE
EXAMPLE
EXAMPLE
testGetPrice_withAge12
EXAMPLE
Helps discovering better test data
Well known techniques(1)
for creating data
Input space partitioning, boundary values, error
guessing.
Cartesian product of test data leads to a combinatorial
explosion.
PIT helps but YOU have to find
PIT tells you when a mutant has survived, but you are in
charge to find out the right test data which will kill it.
(1) Introduction to Software Testing, 2008 – by P. Ammann, J. Offutt
EXAMPLE
mvn org.pitest:pitest-maven:mutationCoverage
>> Generated 8 mutations Killed 7 (88%)
>> Ran 10 tests (1.25 tests per mutation)
=================================================================
- Mutators
=================================================================
> org.pitest...ConditionalsBoundaryMutator
>> Generated 2 Killed 1 (50%)
> KILLED 1 SURVIVED 1 TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
-----------------------------------------------------------------
> org.pitest...ReturnValsMutator
>> Generated 3 Killed 3 (100%)
> KILLED 3 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
EXAMPLE
EXAMPLE
EXAMPLE
testGetPrice_withAge70
EXAMPLE
?!?!?!?!?
EXAMPLE
testGetPrice_withAge70
QUESTIONS ?
PIT: state of the art of mutation testing system
by
Tàrin Gamberìni
CC BY-NC-SA 4.0
CONTACT
Tàrin Gamberìni
tarin.gamberini@jugpadova.it
www.taringamberini.com
SOURCE CODE
https://github.com/taringamberini/linuxday2015.git
CREDITS
Minion with gun - by jpartwork (no license available)
https://nanookofthenerd.wordpress.com/2015/01/30/the-magnificent-maddening-marvelous-
minion-episode-032/
Minion Hands on - by Ceb1031 (CC BY-SA 3.0)
http://parody.wikia.com/wiki/File:Bob_minions_hands.jpg
Canon XTi components after disassembly - by particlem (CC BY 2.0)
https://www.flickr.com/photos/particlem/3860278043/
Continuous Integration - by New Media Labs (no license available)
http://newmedialabs.co.za/approach
Rally car - by mmphotography.it (CC BY-NC 2.0)
https://www.flickr.com/photos/grantuking/9705677549/
Crash Test dummies for sale - by Jack French (CC BY-NC 2.0)
https://www.flickr.com/photos/jackfrench/34523572/
Minion (no license available)
http://thisandthatforkidsblog.com/2013/09/17/easy-to-make-diy-minion-halloween-pumpkin/
Images
Mutant - by minions fans-d6txvph.jpg (no license available)
http://despicableme.wikia.com/wiki/File:Evil_minions_by_minions_fans-d6txvph.jpg
Mutant killed - by Patricia Uribe (no license available)
http://weheartit.com/entry/70334753
Mutant lived - by Carlos Hernández (no license available)
https://gifcept.com/VUQrTOr.gif
PIT logo - by Ling Yeung (CC BY-NC-SA 3.0)
http://pitest.org/about/
Circled Minions - by HARDEEP BHOGAL - (no license available)
https://plus.google.com/109649247879792393053/posts/ghH6tiuUZni?
pid=6004685782480998482&oid=109649247879792393053
Finger puppets – by Gary Leeming (CC BY-NC-SA 2.0)
https://www.flickr.com/photos/grazulis/4754781005/
Questions - by Shinichi Izumi (CC BY-SA)
http://despicableme.wikia.com/wiki/File:Purple_Minion.png
CREDITS
Images

More Related Content

What's hot

Testes De Software - Uma Visão Geral
Testes De Software - Uma Visão GeralTestes De Software - Uma Visão Geral
Testes De Software - Uma Visão Geralpaulo peres
 
risk based testing and regression testing
risk based testing and regression testingrisk based testing and regression testing
risk based testing and regression testingToshi Patel
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJavaKrunal Parmar
 
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driverJúlio de Lima
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing toolsGaurav Paliwal
 
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)SangIn Choung
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with PostmanPostman
 
Istqb 1-소프트웨어테스팅기초
Istqb 1-소프트웨어테스팅기초Istqb 1-소프트웨어테스팅기초
Istqb 1-소프트웨어테스팅기초Jongwon Lee
 
Noções em teste de software e introdução a automação
Noções em teste de software e introdução a automaçãoNoções em teste de software e introdução a automação
Noções em teste de software e introdução a automaçãoSandy Maciel
 
Software Testing Interview Q&A – part 1
Software Testing Interview Q&A – part 1Software Testing Interview Q&A – part 1
Software Testing Interview Q&A – part 1Khoa Bui
 
Percona XtraBackup - New Features and Improvements
Percona XtraBackup - New Features and ImprovementsPercona XtraBackup - New Features and Improvements
Percona XtraBackup - New Features and ImprovementsMarcelo Altmann
 
Istqb 4-테스트설계기법-2015-1
Istqb 4-테스트설계기법-2015-1Istqb 4-테스트설계기법-2015-1
Istqb 4-테스트설계기법-2015-1Jongwon Lee
 

What's hot (20)

Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
Testes De Software - Uma Visão Geral
Testes De Software - Uma Visão GeralTestes De Software - Uma Visão Geral
Testes De Software - Uma Visão Geral
 
Manual testing
Manual testingManual testing
Manual testing
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
 
risk based testing and regression testing
risk based testing and regression testingrisk based testing and regression testing
risk based testing and regression testing
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJava
 
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver
13º É dia de Java: Automação de Testes Funcionais com Selenium Web driver
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing tools
 
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)
애자일 테스트 프랙티스와 사례들 (부제: 협업의 힘)
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with Postman
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Istqb 1-소프트웨어테스팅기초
Istqb 1-소프트웨어테스팅기초Istqb 1-소프트웨어테스팅기초
Istqb 1-소프트웨어테스팅기초
 
Noções em teste de software e introdução a automação
Noções em teste de software e introdução a automaçãoNoções em teste de software e introdução a automação
Noções em teste de software e introdução a automação
 
Software Testing Interview Q&A – part 1
Software Testing Interview Q&A – part 1Software Testing Interview Q&A – part 1
Software Testing Interview Q&A – part 1
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Percona XtraBackup - New Features and Improvements
Percona XtraBackup - New Features and ImprovementsPercona XtraBackup - New Features and Improvements
Percona XtraBackup - New Features and Improvements
 
Introduction to Software Test Automation
Introduction to Software Test AutomationIntroduction to Software Test Automation
Introduction to Software Test Automation
 
Defect Triage by Matt Eakin
Defect Triage by Matt EakinDefect Triage by Matt Eakin
Defect Triage by Matt Eakin
 
Istqb 4-테스트설계기법-2015-1
Istqb 4-테스트설계기법-2015-1Istqb 4-테스트설계기법-2015-1
Istqb 4-테스트설계기법-2015-1
 

Viewers also liked

Commit messages - Good practices
Commit messages - Good practicesCommit messages - Good practices
Commit messages - Good practicesTarin Gamberini
 
MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system Tarin Gamberini
 
Spring security configuration
Spring security configurationSpring security configuration
Spring security configurationHamid Ghorbani
 
How good are your tests?
How good are your tests?How good are your tests?
How good are your tests?Noam Shaish
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with DockerLaura Frank Tacho
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Dockertoffermann
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for TestingMukta Aphale
 
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsI.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsNicolas Fränkel
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsRoy van Rijn
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankDocker, Inc.
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for TestingCarlos Sanchez
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDocker, Inc.
 
Kubernetes your tests! automation with docker on google cloud platform
Kubernetes your tests! automation with docker on google cloud platformKubernetes your tests! automation with docker on google cloud platform
Kubernetes your tests! automation with docker on google cloud platformLivePerson
 

Viewers also liked (16)

Commit messages - Good practices
Commit messages - Good practicesCommit messages - Good practices
Commit messages - Good practices
 
MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system MUTANTS KILLER - PIT: state of the art of mutation testing system
MUTANTS KILLER - PIT: state of the art of mutation testing system
 
Apache Maven
Apache MavenApache Maven
Apache Maven
 
Spring security configuration
Spring security configurationSpring security configuration
Spring security configuration
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
How good are your tests?
How good are your tests?How good are your tests?
How good are your tests?
 
Efficient Parallel Testing with Docker
Efficient Parallel Testing with DockerEfficient Parallel Testing with Docker
Efficient Parallel Testing with Docker
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Docker
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
 
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
Javantura v3 - Mutation Testing for everyone – Nicolas FränkelJavantura v3 - Mutation Testing for everyone – Nicolas Fränkel
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
 
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your testsI.T.A.K.E Unconference - Mutation testing to the rescue of your tests
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
 
Kill the mutants - A better way to test your tests
Kill the mutants - A better way to test your testsKill the mutants - A better way to test your tests
Kill the mutants - A better way to test your tests
 
Efficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura FrankEfficient Parallel Testing with Docker by Laura Frank
Efficient Parallel Testing with Docker by Laura Frank
 
Using Docker for Testing
Using Docker for TestingUsing Docker for Testing
Using Docker for Testing
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
 
Kubernetes your tests! automation with docker on google cloud platform
Kubernetes your tests! automation with docker on google cloud platformKubernetes your tests! automation with docker on google cloud platform
Kubernetes your tests! automation with docker on google cloud platform
 

Similar to MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system

STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Project
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupDror Helper
 
Must.kill.mutants. TopConf Tallinn 2016
Must.kill.mutants. TopConf Tallinn 2016Must.kill.mutants. TopConf Tallinn 2016
Must.kill.mutants. TopConf Tallinn 2016Gerald Muecke
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Andrzej Jóźwiak
 
Must.Kill.Mutants. Agile Testing Days 2017
Must.Kill.Mutants. Agile Testing Days 2017Must.Kill.Mutants. Agile Testing Days 2017
Must.Kill.Mutants. Agile Testing Days 2017Gerald Muecke
 
Mutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsMutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsAri Waller
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdfgauravavam
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 
Mutation Testing with PIT
Mutation Testing with PITMutation Testing with PIT
Mutation Testing with PITRafał Leszko
 
Java 8 - Lambdas and much more
Java 8 - Lambdas and much moreJava 8 - Lambdas and much more
Java 8 - Lambdas and much moreAlin Pandichi
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsTomek Kaczanowski
 
Pro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise ApplicationsPro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise ApplicationsStephen Chin
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the typeWim Godden
 

Similar to MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system (20)

STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Must.kill.mutants. TopConf Tallinn 2016
Must.kill.mutants. TopConf Tallinn 2016Must.kill.mutants. TopConf Tallinn 2016
Must.kill.mutants. TopConf Tallinn 2016
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Agile mobile
Agile mobileAgile mobile
Agile mobile
 
Google guava
Google guavaGoogle guava
Google guava
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Must.Kill.Mutants. Agile Testing Days 2017
Must.Kill.Mutants. Agile Testing Days 2017Must.Kill.Mutants. Agile Testing Days 2017
Must.Kill.Mutants. Agile Testing Days 2017
 
Mutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The BugsMutation Testing: Start Hunting The Bugs
Mutation Testing: Start Hunting The Bugs
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
Mutation Testing with PIT
Mutation Testing with PITMutation Testing with PIT
Mutation Testing with PIT
 
Java 8 - Lambdas and much more
Java 8 - Lambdas and much moreJava 8 - Lambdas and much more
Java 8 - Lambdas and much more
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
Pro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise ApplicationsPro Java Fx – Developing Enterprise Applications
Pro Java Fx – Developing Enterprise Applications
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
Kpi driven-java-development-fn conf
Kpi driven-java-development-fn confKpi driven-java-development-fn conf
Kpi driven-java-development-fn conf
 

Recently uploaded

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 

Recently uploaded (20)

%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system

  • 1. PIT: state of the art of mutation testing system Revised edition MUTANTS KILLER by Tàrin Gamberìni - CC BY-NC-SA 4.0
  • 2. Lavora da sempre con tecnologie Java-based free e Open Source presso la Regione Emilia-Romagna Si interessa di Object Oriented Design, Design Patterns, Build Automation, Testing e Continuous Integration TÀRIN GAMBERÌNI Partecipa attivamente al Java User Group Padova
  • 3. Unit Testing Test-Driven Development (TDD) Continuous Integration Code Coverage Mutation Testing DEVELOPMENT
  • 4. UNIT TESTING & TDD The proof of working code Refactor with confidence (regression) Improve code design Living documentation TDD extremely valuable in some context
  • 5. CONTINUOUS INTEGRATION Maintain a single source repository Automate the build Cheap statics for code quality Automate unit & integration tests Catch problems fast
  • 6. LINE COVERAGE Is a measure of tested source code line, statement, branch, … , coverage
  • 7. LINE COVERAGE 100% Only able to identify not tested code Doesn't check tests are able to detect faults Measures only which code is executed by tests
  • 8. WEAK TESTS public static String foo( boolean b ) { if ( b ) { performVitallyImportantBusinessFunction(); return "OK"; } return "FAIL"; } @Test public void shouldFailWhenGivenFalse() { assertEquals("FAIL", foo( false )); } @Test public void shouldBeOkWhenGivenTrue() { assertEquals("OK", foo( true )); } The untested side effect
  • 9. WEAK TESTS public static String foo( boolean b ) { if ( b ) { performVitallyImportantBusinessFunction(); return "OK"; } return "FAIL"; } @Test public void shouldFailWhenGivenFalse() { assertEquals("FAIL", foo( false )); } @Test public void shouldBeOkWhenGivenTrue() { assertEquals("OK", foo( true )); } The untested side effect
  • 10. WEAK TESTS public static String foo( int i ) { if ( i >= 0 ) { return "foo"; } else { return "bar"; } } @Test public void shouldReturnFooWhenGiven1() { assertEquals("foo", foo( 1 )); } @Test public void shouldReturnBarWhenGivenMinus1() { assertEquals("bar", foo( -1 )); } The missing boundary test
  • 11. WEAK TESTS public static String foo( int i ) { if ( i >= 0 ) { return "foo"; } else { return "bar"; } } @Test public void shouldReturnBarWhenGiven1() { assertEquals("bar", foo( 1 )); } @Test public void shouldReturnFooWhenGivenZero() { assertEquals("foo", foo( 0 )); } @Test public void shouldReturnFooWhenGivenMinus1() { assertEquals("foo", foo( -1 )); } The missing boundary test
  • 12. WEAK TESTS public static String foo(Collaborator c, boolean b) { if ( b ) { return c.performAction(); } return "FOO"; } @Test public void shouldPerformActionWhenGivenTrue() { foo(mockCollaborator,true); verify(mockCollaborator).performAction(); } @Test public void shouldNotPerformActionWhenGivenFalse() { foo(mockCollaborator,false); verify(never(),mockCollaborator).performAction(); } The myopic mockist
  • 13. WEAK TESTS public static String foo(Collaborator c, boolean b) { if ( b ) { return c.performAction(); } return "FOO"; } @Test public void shouldPerformActionWhenGivenTrue() { String result = foo(mockCollaborator,true); verify(mockCollaborator).performAction(); assertEquals("MOCK", result); } @Test public void shouldNotPerformActionWhenGivenFalse() { String result = foo(mockCollaborator,false); verify(never(),mockCollaborator).performAction(); assertEquals("FOO", result); } The myopic mockist
  • 14. WHO TESTS THE TESTS ?
  • 15. MUTATION TESTING ● originally proposed by Richard Lipton as a student in 1971 ● 1st implementation tool was a PhD work in 1980 ● recent availability of higher computing power has led to a resurgence ● expose weaknesses in tests (quality)
  • 16. MUTATION TESTING ● originally proposed by Richard Lipton as a student in 1971 ● 1st implementation tool was a PhD work in 1980 ● recent availability of higher computing power has led to a resurgence ● expose weaknesses in tests (quality)
  • 17. MUTATION Is a small change in your program original mutated
  • 19. MUTATION TESTING generate lots of mutants run all tests against all mutants check mutants: killed or lived?
  • 20. MUTANT KILLED Proof of detected mutated code Test is testing source code properly If the unit test fails
  • 21. MUTANT LIVED Proof of not detected mutated code If the unit test succeed Test isn't testing source code
  • 22.
  • 23. PIT: BASIC CONCEPTS Applies a configurable set of mutators Generates reports with test results Manipulates the byte code generated by compiling your code
  • 24. PIT: MUTATORS Conditionals Boundary < → <= <= → < > → >= >= → >
  • 25. PIT: MUTATORS Negate Conditionals == → != != → == <= → > >= → < < → >= > → <=
  • 26. PIT: MUTATORS Math Mutator + → - - → + * → / / → * % → * & → | | → & ^ → & << → >> >> → << >>> → <<
  • 27. PIT: MUTATORS Remove Conditionals if (a == b) { // do something } if (true) { // do something } →
  • 28. PIT: MUTATORS Return Values Mutator Conditionals public Object foo() { return new Object(); } public Object foo() { new Object(); return null; } →
  • 29. PIT: MUTATORS Void Method Call Mutator public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } → public int foo() { int i = 5; return i; } public void doSomething(int i) { // does something }
  • 30. PIT: MUTATORS Many others Activated by default Conditionals Boundary Mutator - Increments Mutator - Invert Negatives Mutator - Math Mutator - Negate Conditionals Mutator - Return Values Mutator - Void Method Calls Mutator Deactivated by default Constructor Calls Mutator - Inline Constant Mutator - Non Void Method Calls Mutator - Remove Conditionals Mutator - Experimental Member Variable Mutator - Experimental Switch Mutator
  • 31. PIT: MUTATORS Application field Traditional and class PIT is suitable for "ordinary" java programs because mutators change "ordinary" java language instructions. The right mutator for the right application field Not the best option if you are interesting testing: ● Aspect Java programs, try AjMutator ● Concurrent programs, try ExMan ● Mutators for: reflection, java annotations, generics, … ?
  • 32. HOW PIT WORKS Running the tests public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } Your program
  • 33. HOW PIT WORKS Running the tests PIT runs traditional line coverage analysis
  • 34. HOW PIT WORKS Running the tests Generates mutant by applaying mutators public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } mutant 2 public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } mutant 1 public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } mutant 3
  • 35. HOW PIT WORKS Brute force x = 9 100 tests x 1.2ms = 0.12s 0.12s x 10000 mutants = 20min !!! 1000 class x 10 mutants per class = 10000 mutants
  • 36. HOW PIT WORKS Running the tests PIT leverages line coverage to discard tests that do not exercise the mutated line of code public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } public int foo() { int i = 5; doSomething(i); return i; } public void doSomething(int i) { // does something } mutant 3
  • 37. HOW PIT WORKS Extremely fast x = 1 x = 1 x = 2 4 < 9
  • 38. HOW PIT WORKS Outcomes ● Killed, Lived ● No coverage: the same as Lived except there were no tests that exercised the mutated line of code ● Non viable: bytecode was in some way invalid ● Timed Out: infinite loop ● Memory error: mutation that increases the amount of memory used ● Run error: a large number of run errors probably means something went wrong
  • 39. PIT ECOSYSTEM Tools Command line Other IDEs as a Java application ( )
  • 44. EXAMPLE mvn org.pitest:pitest-maven:mutationCoverage >> Generated 8 mutations Killed 6 (75%) >> Ran 11 tests (1.38 tests per mutation) ================================================================= - Mutators ================================================================= > org.pitest...ConditionalsBoundaryMutator >> Generated 2 Killed 0 (0%) > KILLED 0 SURVIVED 2 TIMED_OUT 0 NON_VIABLE 0 > MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 > NO_COVERAGE 0 ----------------------------------------------------------------- > org.pitest...ReturnValsMutator >> Generated 3 Killed 3 (100%) > KILLED 3 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 > MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 > NO_COVERAGE 0
  • 48. EXAMPLE Helps discovering better test data Well known techniques(1) for creating data Input space partitioning, boundary values, error guessing. Cartesian product of test data leads to a combinatorial explosion. PIT helps but YOU have to find PIT tells you when a mutant has survived, but you are in charge to find out the right test data which will kill it. (1) Introduction to Software Testing, 2008 – by P. Ammann, J. Offutt
  • 49. EXAMPLE mvn org.pitest:pitest-maven:mutationCoverage >> Generated 8 mutations Killed 7 (88%) >> Ran 10 tests (1.25 tests per mutation) ================================================================= - Mutators ================================================================= > org.pitest...ConditionalsBoundaryMutator >> Generated 2 Killed 1 (50%) > KILLED 1 SURVIVED 1 TIMED_OUT 0 NON_VIABLE 0 > MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 > NO_COVERAGE 0 ----------------------------------------------------------------- > org.pitest...ReturnValsMutator >> Generated 3 Killed 3 (100%) > KILLED 3 SURVIVED 0 TIMED_OUT 0 NON_VIABLE 0 > MEMORY_ERROR 0 NOT_STARTED 0 STARTED 0 RUN_ERROR 0 > NO_COVERAGE 0
  • 55. QUESTIONS ? PIT: state of the art of mutation testing system by Tàrin Gamberìni CC BY-NC-SA 4.0
  • 58. CREDITS Minion with gun - by jpartwork (no license available) https://nanookofthenerd.wordpress.com/2015/01/30/the-magnificent-maddening-marvelous- minion-episode-032/ Minion Hands on - by Ceb1031 (CC BY-SA 3.0) http://parody.wikia.com/wiki/File:Bob_minions_hands.jpg Canon XTi components after disassembly - by particlem (CC BY 2.0) https://www.flickr.com/photos/particlem/3860278043/ Continuous Integration - by New Media Labs (no license available) http://newmedialabs.co.za/approach Rally car - by mmphotography.it (CC BY-NC 2.0) https://www.flickr.com/photos/grantuking/9705677549/ Crash Test dummies for sale - by Jack French (CC BY-NC 2.0) https://www.flickr.com/photos/jackfrench/34523572/ Minion (no license available) http://thisandthatforkidsblog.com/2013/09/17/easy-to-make-diy-minion-halloween-pumpkin/ Images
  • 59. Mutant - by minions fans-d6txvph.jpg (no license available) http://despicableme.wikia.com/wiki/File:Evil_minions_by_minions_fans-d6txvph.jpg Mutant killed - by Patricia Uribe (no license available) http://weheartit.com/entry/70334753 Mutant lived - by Carlos Hernández (no license available) https://gifcept.com/VUQrTOr.gif PIT logo - by Ling Yeung (CC BY-NC-SA 3.0) http://pitest.org/about/ Circled Minions - by HARDEEP BHOGAL - (no license available) https://plus.google.com/109649247879792393053/posts/ghH6tiuUZni? pid=6004685782480998482&oid=109649247879792393053 Finger puppets – by Gary Leeming (CC BY-NC-SA 2.0) https://www.flickr.com/photos/grazulis/4754781005/ Questions - by Shinichi Izumi (CC BY-SA) http://despicableme.wikia.com/wiki/File:Purple_Minion.png CREDITS Images