SlideShare a Scribd company logo
@nicolas_frankel
Mutation Testing to the
rescue of your tests
@nicolas_frankel
• Developer, team lead, architect,
whatever it takes
• Recent Developer Advocate
• Kotlin fanboy
Me, myself and I
@nicolas_frankel
Hazelcast
HAZELCAST IMDG is an operational,
in-memory, distributed computing
platform that manages data using
in-memory storage, and performs
parallel execution for breakthrough
application speed and scale.
HAZELCAST JET is the ultra fast,
application embeddable, 3rd
generation stream processing
engine for low latency batch
and stream processing.
@nicolas_frankel
• Unit Testing
• Integration Testing
• End-to-end Testing
• Performance Testing
• Penetration Testing
• Exploratory Testing
• etc.
Many kinds of testing
@nicolas_frankel
Ensure the quality of the production
code
Their only single goal
5
@nicolas_frankel
How to check the quality of the
testing code?
The problem
6
@nicolas_frankel
“Code coverage is a measure used to
describe the degree to which the
source code of a program is tested”
--Wikipedia
http://en.wikipedia.org/wiki/Code_coverage
Code coverage
7
@nicolas_frankel
Check whether a source code line is
executed during a test
• Or Branch Coverage
Measuring Code Coverage
@nicolas_frankel #mutationtesting #devexperience18
8
@nicolas_frankel
Computing Code Coverage
CC =
Lexecuted
Ltotal
*100
• CC: Code
Coverage
(in percent)
• Lexecuted: Number
of executed lines
of code
• Ltotal: Number of
total lines of
code
@nicolas_frankel
• JaCoCo
• Clover
• Cobertura
• etc.
Java Tools for Code Coverage
10
@nicolas_frankel
“Is 100% code coverage realistic? Of
course it is. If you can write a line of
code, you can write another that
tests it.”
Robert Martin (Uncle Bob)
https://twitter.com/unclebobmartin/status/55966
620509667328
100% Code Coverage?
11
@nicolas_frankel
@Test
public void add_should_add() {
new Math().add(1, 1);
}
Assertless testing
But, where is the assert?
As long as the Code Coverage is OK…
@nicolas_frankel
• Any metric can be gamed!
• Code coverage is a metric…
⇒ Code coverage can be gamed
• On purpose
• Or by accident
Code coverage as a measure of quality
13
@nicolas_frankel
• Code Coverage lulls you into a false
sense of security…
Code coverage as a measure of quality
14
@nicolas_frankel
• Code coverage cannot ensure test
quality
• Is there another way?
• Mutation Testing to the rescue!
The problem still stands
15
@nicolas_frankel
The Cast
William Stryker
Original Source Code
Jason Stryker
Modified Source Code
a.k.a “The Mutant”
@nicolas_frankel
public class Math {
public int add(int i1, int i2) {
return i1 + i2;
}
}
public class Math {
public int add(int i1, int i2) {
return i1 - i2;
}
}
@nicolas_frankel
Standard testing
✔Execute Test
@nicolas_frankel
Mutation testing
?Execute SAME Test
Mutation
@nicolas_frankel
Mutation testing
✗
✔Execute SAME Test
Execute SAME Test
Mutant Killed
Mutant Survived
@nicolas_frankel
• Surviving means changing the
source code did not change the
test result  Bad!
• Killed means changing the source
code changed the test result 
Good!
Killed or Surviving?
21
@nicolas_frankel
Test the code
public class Math {
public int add(int i1, int i2) {
return i1 + i2;
}
}
✔Execute Test
@Test
public void add_should_add() {
new Math().add(1, 1);
}
@nicolas_frankel
✔Execute Test
Surviving mutant
public class Math {
public int add(int i1, int i2) {
return i1 - i2;
}
}
@Test
public void add_should_add() {
new Math().add(1, 1);
}
@nicolas_frankel
Test the code
✔Execute Test
public class Math {
public int add(int i1, int i2) {
return i1 + i2;
}
}
@Test
public void add_should_add() {
new Math().add(1, 1);
Assert.assertEquals(sum, 2);
}
@nicolas_frankel
Killed mutant
✗Execute SAME Test
public class Math {
public int add(int i1, int i2) {
return i1 + i2;
}
}
@Test
public void add_should_add() {
new Math().add(1, 1);
Assert.assertEquals(sum, 2);
}
@nicolas_frankel
• PIT is a tool for Mutation testing
• Available as
• Command-line tool
• Ant target
• Maven plugin
Mutation Testing in Java
26
@nicolas_frankel
Mutators are patterns applied to
source code to produce mutations
Mutators
27
@nicolas_frankel
PIT mutators sample
Name Example source Result
Conditionals Boundary > >=
Negate Conditionals == !=
Remove Conditionals foo == bar true
Math + -
Increments foo++ foo--
Invert Negatives -foo foo
Inline Constant static final FOO= 42 static final FOO = 43
Return Values return true return false
Void Method Call System.out.println("foo")
Non Void Method Call long t = System.currentTimeMillis() long t = 0
Constructor Call Date d = new Date() Date d = null;
@nicolas_frankel
Conditionals Boundary
• Potential serious bug hiding there
• if (foo > bar)
Important mutators
29
@nicolas_frankel
Void Method Call
• Assert.checkNotNull()
• connection.close()
Important mutators
30
@nicolas_frankel
It’s not because the IDE generates
code safely that it will never change
• equals()
• hashCode()
Remember
31
@nicolas_frankel
@nicolas_frankel
Sh… (bad stuff) happens
• False positives
• Imperfect
• Sloooooooooooooooow
@nicolas_frankel
if (p < 0)
...
// changed condition boundary -> survived:
if (p > 0)
...
return 0;
Pit is imperfect
@nicolas_frankel
void rebootMachine() {
// removed method call:
checkUserPermissions();
Runtime.getRuntime().exec("reboot");
}
Pit is imperfect
@nicolas_frankel
• Analyze test code
• For each class under test
• For each mutator
• Create mutation
• For each mutation
• Run test
• Analyze result
• Aggregate results
Why so slow?
36
@nicolas_frankel
• Increase number of threads  
• Set a limited a set of mutators
• Limit scope of target classes
• Limit number of tests
• Limit dependency distance
• Use incremental analysis  
• Don’t bind to the test phase  
• Use scmMutationCoverage
Workarounds
37
@nicolas_frankel
• Metadata stored between runs
• Mutant will not be checked again, if:
• killed, and neither class nor test have changed
• survived, and there are no new/changed tests for it
Incremental analysis
@nicolas_frankel
• Checks the relevance of your unit
tests
• Points out potential bugs
Is Mutation Testing the Silver Bullet?
39
@nicolas_frankel
• Validate the assembled application
• Integration Testing
• Check the performance
• Performance Testing
• Look out for display bugs
• End-to-end testing
• Etc.
The rest is up to you
40
@nicolas_frankel
• Don’t test to achieve 100%
coverage
• Test because it saves money in the
long run
• Prioritize:
• Business-critical code
• Complex code
Testing is about ROI
41
@nicolas_frankel
• https://blog.frankel.ch/
• @nicolas_frankel
• https://git.io/vznQK
Thanks a lot!

More Related Content

PPTX
Codemash - Mutation testing to the rescue of your tests
PPTX
TestCon Europe - Mutation Testing to the Rescue of Your Tests
PPTX
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
PPTX
Craft-Conf - Improve your Tests with Mutation Testing
PPTX
GeeCON - Improve your tests with Mutation Testing
PPTX
ConFoo - Improve your tests with mutation testing
PPTX
Voxxed Days Athens - Improve your tests with Mutation Testing
PPTX
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests
Codemash - Mutation testing to the rescue of your tests
TestCon Europe - Mutation Testing to the Rescue of Your Tests
Javantura v3 - Mutation Testing for everyone – Nicolas Fränkel
Craft-Conf - Improve your Tests with Mutation Testing
GeeCON - Improve your tests with Mutation Testing
ConFoo - Improve your tests with mutation testing
Voxxed Days Athens - Improve your tests with Mutation Testing
I.T.A.K.E Unconference - Mutation testing to the rescue of your tests

Similar to Java Dominicano - Mutation testing (20)

PPTX
DevExperience - Improve your tests with mutation testing
PPTX
Joker - Improve your tests with mutation testing
PDF
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
PPTX
Kill the mutants and test your tests - Roy van Rijn
PDF
Kill the mutants - A better way to test your tests
PDF
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
PPT
Mutation Testing and MuJava
PDF
MUTANTS KILLER - PIT: state of the art of mutation testing system
PDF
Can You Trust Your Tests? (Agile Tour 2015 Kaunas)
PDF
50120140502017
PDF
Mutation testing in Java
PDF
Mutation testing with PIT
PDF
Mutation testing pixels camp 2019
PPTX
Mateusz Bryła - Mutation testing
PDF
Must.kill.mutants. TopConf Tallinn 2016
PPTX
Mutation Testing
PDF
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
PPTX
Mutation Testing - Ruby Edition
PDF
Mutation Testing
PDF
Must.Kill.Mutants. Agile Testing Days 2017
DevExperience - Improve your tests with mutation testing
Joker - Improve your tests with mutation testing
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants - A better way to test your tests
Vaidas Pilkauskas and Tadas Ščerbinskas - Can you trust your tests?
Mutation Testing and MuJava
MUTANTS KILLER - PIT: state of the art of mutation testing system
Can You Trust Your Tests? (Agile Tour 2015 Kaunas)
50120140502017
Mutation testing in Java
Mutation testing with PIT
Mutation testing pixels camp 2019
Mateusz Bryła - Mutation testing
Must.kill.mutants. TopConf Tallinn 2016
Mutation Testing
Javazone 2019 - Mutants to the rescue: How effective are your unit tests?
Mutation Testing - Ruby Edition
Mutation Testing
Must.Kill.Mutants. Agile Testing Days 2017
Ad

More from Nicolas Fränkel (20)

PPTX
SnowCamp - Adding search to a legacy application
PPTX
Un CV de dévelopeur toujours a jour
PPTX
Zero-downtime deployment on Kubernetes with Hazelcast
PDF
jLove - A Change-Data-Capture use-case: designing an evergreen cache
PPTX
BigData conference - Introduction to stream processing
PPTX
ADDO - Your own Kubernetes controller, not only in Go
PPTX
OSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java application
PPTX
GeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cache
PPTX
JavaDay Istanbul - 3 improvements in your microservices architecture
PPTX
OSCONF Hyderabad - Shorten all URLs!
PPTX
Devclub.lv - Introduction to stream processing
PPTX
OSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring Boot
PPTX
JOnConf - A CDC use-case: designing an Evergreen Cache
PPTX
London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...
PPTX
JUG Tirana - Introduction to data streaming
PPTX
Java.IL - Your own Kubernetes controller, not only in Go!
PPTX
vJUG - Introduction to data streaming
PPTX
London Java Community - An Experiment in Continuous Deployment of JVM applica...
PPTX
OSCONF - Your own Kubernetes controller: not only in Go
PPTX
vKUG - Migrating Spring Boot apps from annotation-based config to Functional
SnowCamp - Adding search to a legacy application
Un CV de dévelopeur toujours a jour
Zero-downtime deployment on Kubernetes with Hazelcast
jLove - A Change-Data-Capture use-case: designing an evergreen cache
BigData conference - Introduction to stream processing
ADDO - Your own Kubernetes controller, not only in Go
OSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java application
GeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cache
JavaDay Istanbul - 3 improvements in your microservices architecture
OSCONF Hyderabad - Shorten all URLs!
Devclub.lv - Introduction to stream processing
OSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring Boot
JOnConf - A CDC use-case: designing an Evergreen Cache
London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...
JUG Tirana - Introduction to data streaming
Java.IL - Your own Kubernetes controller, not only in Go!
vJUG - Introduction to data streaming
London Java Community - An Experiment in Continuous Deployment of JVM applica...
OSCONF - Your own Kubernetes controller: not only in Go
vKUG - Migrating Spring Boot apps from annotation-based config to Functional
Ad

Recently uploaded (20)

PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Essential Infomation Tech presentation.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
history of c programming in notes for students .pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Digital Strategies for Manufacturing Companies
CHAPTER 2 - PM Management and IT Context
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
wealthsignaloriginal-com-DS-text-... (1).pdf
Understanding Forklifts - TECH EHS Solution
Essential Infomation Tech presentation.pptx
Design an Analysis of Algorithms I-SECS-1021-03
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
history of c programming in notes for students .pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PTS Company Brochure 2025 (1).pdf.......
Odoo POS Development Services by CandidRoot Solutions
Upgrade and Innovation Strategies for SAP ERP Customers
Digital Strategies for Manufacturing Companies

Java Dominicano - Mutation testing

Editor's Notes

  • #11: All are integrated in Maven JaCoCo is also integrated into Sonar out-of-the-box
  • #29: There are also experimental mutators http://pitest.org/quickstart/mutators/
  • #30: Picture by Nevit Dilmen https://commons.wikimedia.org/wiki/File:Rabbit_Grasshoper_Mutant-01611-nevit.jpg