SlideShare a Scribd company logo
Mutation Testing with PIT
Rafał Leszko
@RafalLeszko
rafalleszko.com
Hazelcast
About me
● Integration Team Lead at Hazelcast
● Worked at Google and CERN
● Author of the book "Continuous Delivery
with Docker and Jenkins"
● Trainer and conference speaker
● Live in Kraków, Poland
About Hazelcast
● Distributed Company
● Open Source Software
● 140+ Employees
● Products:
○ Hazelcast IMDG
○ Hazelcast Jet
○ Hazelcast Cloud
@Hazelcast
Mutation testing with PIT
Mutation testing with PIT
I wrote code for the
spacecraft.
How do you that it
works?
Hmm...
I just know
I feel it
I feel it
I feel it
I feel it
Mutation testing with PIT
Mutation testing with PIT
$327.6 million
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
I wrote code for the
spacecraft.
How do you that it
works?
I wrote unit tests!
How do you know
that your tests work?
Hmm...
really?
code
code
test
code
test
test
code
test
test
test
code
test
test
test
test
Mutation testing with PIT
Does testing make
any sense at all?
return a + b;
return a + b;
Coverage does not
prove that you have
TESTED every line.
All it proves is that you
have EXECUTED every
line. And that is a big
difference.
public class Calculator {
public int sum(int a, int b) {
return a + b;
}
}
@Test
public void
force100PercentCoverage() {
calculator.sum(0, 0);
}
Richard Lipton found the
good answer in 1971
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
"If you want to know if a test
suite has properly checked
some code, introduce a bug"
return a + b;
return a - b;
Is it the whole idea behind the
mutation testing?
Actually, Yes!
● Artificial bug: MUTATION OPERATION
● Artificial bug: MUTATION OPERATION
● Code with artificial bug: MUTANT
● Artificial bug: MUTATION OPERATION
● Code with artificial bug: MUTANT
● When the test fails on mutant: KILLED the
mutant
● Artificial bug: MUTATION OPERATION
● Code with artificial bug: MUTANT
● When the test fails on mutant: KILLED the
mutant
● When the test succeeds on mutant:
mutant SURVIVED
return a - b;
KILLED SURVIVED
killing is good
My code is much more
complex than adding two
numbers!
Mutation
Operators
Math
+ to - * to /
- to + / to *
Boundary
< to <= > to >=
<= to < <= to >
Negate
== to !=
>= to <
Complex
Remove IFs
Complex
Remove IFs Remove method calls
Complex
Remove IFs
Modify return
Remove method calls
Complex
Remove IFs
Modify constantsModify return
Remove method calls
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Do I need to change the
code on my own?
PIT Mutation Testing
public class Calculator {
public int sum(int a, int b) {
return a + b;
}
}
@Test
public
void force100PercentCoverage() {
calculator.sum(0, 0);
}
DEMO
> MathMutator
>> Generated 1 Killed 0 (0%)
> KILLED 0 SURVIVED 1
> TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0
> STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
@Test public void
Should_ReturnSum_When_SummingTwoValues() {
// given
int a = 1;
int b = 2;
// when
int result = calculator.sum(a, b);
// then
assertThat(result).isEqualTo(3);
}
> MathMutator
>> Generated 1 Killed 1 (100%)
> KILLED 1 SURVIVED 0
> TIMED_OUT 0 NON_VIABLE 0
> MEMORY_ERROR 0 NOT_STARTED 0
> STARTED 0 RUN_ERROR 0
> NO_COVERAGE 0
Do I need to read the
console?
DEMO
How about bigger
projects?
Hazelcast Kubernetes Plugin
● 5000 LOC
● 12 classes
DEMO
Why NASA engineers
didn't use it in 1998?
1971
Richard
Lipton
1971
Richard
Lipton
2000
1971
Richard
Lipton
2000 2012
1
Equivalent
Mutants
if (a >= 100) {
throw new IllegalArgumentException();
}
if (a < 100) {
fooBar();
}
if (a >= 100) {
throw new IllegalArgumentException();
}
if (a < 100) {
fooBar();
}
2
Slow
Performance
Mutation testing with PIT
Mutation testing with PIT
return a + b;
return a + b;
return a + b;
return a - b
return 0
return a + b;
return a - b
return 0
:)
What about my
team?
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Main class paradox
Mutation testing with PIT
Mutation testing with PIT
// given
// given
// when
// given
// when
?
What to do with people
who write tests without
assertions?
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Do people really use
mutation testing?
Mutation testing with PIT
Mutation testing with PIT
Test your tests
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Mutation testing with PIT
Thank You!
Rafał Leszko
@RafalLeszko
rafalleszko.com

More Related Content

PDF
Mutation Testing with PIT
PDF
TDD: What is it good for?
PDF
Python 1 liners
PPTX
From clever code to better code
PDF
C++ TUTORIAL 2
PDF
Beginning Python
PPT
Java performance
PPTX
TDD? Sure, but What About My Legacy Code?
Mutation Testing with PIT
TDD: What is it good for?
Python 1 liners
From clever code to better code
C++ TUTORIAL 2
Beginning Python
Java performance
TDD? Sure, but What About My Legacy Code?

What's hot (18)

PPTX
Generating characterization tests for legacy code
PDF
Solved Practice Problems For the C++ Exams
PDF
Talk Code
PDF
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
PPTX
Building unit tests correctly
PPTX
Unit Testing with Foq
PPTX
Legacy Dependency Kata v2.0
PDF
關於測試,我說的其實是......
PPTX
Automatically Documenting Program Changes
PPSX
Nested loops
PPT
Functional techniques in Ruby
PDF
Operator overloading
PDF
Practiceproblems(1)
ODP
Automated Refactoring
PPTX
Presentation1 computer shaan
PPTX
From clever code to better code
PDF
An introduction to property based testing
PPT
Generating characterization tests for legacy code
Solved Practice Problems For the C++ Exams
Talk Code
Project_Euler_No_104_Pandigital_Fibonacci_ends
 
Building unit tests correctly
Unit Testing with Foq
Legacy Dependency Kata v2.0
關於測試,我說的其實是......
Automatically Documenting Program Changes
Nested loops
Functional techniques in Ruby
Operator overloading
Practiceproblems(1)
Automated Refactoring
Presentation1 computer shaan
From clever code to better code
An introduction to property based testing
Ad

Similar to Mutation testing with PIT (20)

PDF
Tdd is not about testing
PDF
TDD reloaded - JUGTAA 24 Ottobre 2012
PDF
Build tic tac toe with javascript (4:11 dc)
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PPTX
Kill the mutants and test your tests - Roy van Rijn
PDF
Kill the mutants - A better way to test your tests
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
PPTX
Mutation Testing
PPT
00_Introduction to Java.ppt
PPT
C#, What Is Next?
PDF
Programming exercises
PPTX
20.1 Java working with abstraction
PPTX
Building unit tests correctly with visual studio 2013
PDF
Of complicacy of programming, or won't C# save us?
PDF
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
PDF
Tdd with python unittest for embedded c
PDF
MUTANTS KILLER - PIT: state of the art of mutation testing system
PDF
Priming Java for Speed at Market Open
PPTX
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
PPTX
Tdd is not about testing (OOP)
Tdd is not about testing
TDD reloaded - JUGTAA 24 Ottobre 2012
Build tic tac toe with javascript (4:11 dc)
Test-Driven Design Insights@DevoxxBE 2023.pptx
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants - A better way to test your tests
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
Mutation Testing
00_Introduction to Java.ppt
C#, What Is Next?
Programming exercises
20.1 Java working with abstraction
Building unit tests correctly with visual studio 2013
Of complicacy of programming, or won't C# save us?
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Tdd with python unittest for embedded c
MUTANTS KILLER - PIT: state of the art of mutation testing system
Priming Java for Speed at Market Open
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
Tdd is not about testing (OOP)
Ad

More from Rafał Leszko (20)

PDF
Build Your Kubernetes Operator with the Right Tool!
PDF
Distributed Locking in Kubernetes
PDF
Architectural patterns for high performance microservices in kubernetes
PDF
Architectural caching patterns for kubernetes
PDF
Architectural patterns for caching microservices
PDF
[jLove 2020] Where is my cache architectural patterns for caching microservi...
PDF
Where is my cache architectural patterns for caching microservices by example
PDF
Architectural caching patterns for kubernetes
PDF
Build your operator with the right tool
PDF
5 levels of high availability from multi instance to hybrid cloud
PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
5 Levels of High Availability: From Multi-instance to Hybrid Cloud
PDF
Where is my cache architectural patterns for caching microservices by example
PDF
Where is my cache architectural patterns for caching microservices by example
PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
[DevopsDays India 2019] Where is my cache? Architectural patterns for caching...
PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
PDF
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
PDF
Mutation Testing - Voxxed Days Cluj-Napoca 2017
Build Your Kubernetes Operator with the Right Tool!
Distributed Locking in Kubernetes
Architectural patterns for high performance microservices in kubernetes
Architectural caching patterns for kubernetes
Architectural patterns for caching microservices
[jLove 2020] Where is my cache architectural patterns for caching microservi...
Where is my cache architectural patterns for caching microservices by example
Architectural caching patterns for kubernetes
Build your operator with the right tool
5 levels of high availability from multi instance to hybrid cloud
Where is my cache? Architectural patterns for caching microservices by example
5 Levels of High Availability: From Multi-instance to Hybrid Cloud
Where is my cache architectural patterns for caching microservices by example
Where is my cache architectural patterns for caching microservices by example
Where is my cache? Architectural patterns for caching microservices by example
[DevopsDays India 2019] Where is my cache? Architectural patterns for caching...
Where is my cache? Architectural patterns for caching microservices by example
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Mutation Testing - Voxxed Days Cluj-Napoca 2017

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
top salesforce developer skills in 2025.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Digital Strategies for Manufacturing Companies
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
medical staffing services at VALiNTRY
PPTX
Introduction to Artificial Intelligence
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPT
Introduction Database Management System for Course Database
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Transform Your Business with a Software ERP System
Which alternative to Crystal Reports is best for small or large businesses.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
top salesforce developer skills in 2025.pdf
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
VVF-Customer-Presentation2025-Ver1.9.pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Digital Strategies for Manufacturing Companies
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
medical staffing services at VALiNTRY
Introduction to Artificial Intelligence
Understanding Forklifts - TECH EHS Solution
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Introduction Database Management System for Course Database
CHAPTER 2 - PM Management and IT Context
How to Migrate SBCGlobal Email to Yahoo Easily
2025 Textile ERP Trends: SAP, Odoo & Oracle
Transform Your Business with a Software ERP System

Mutation testing with PIT