SlideShare a Scribd company logo
1 of 35
An event proudly designed by
Mutation Testing to the
rescue of your tests
@nicolas_frankel
Me, Myself and I
• By day
• Hybris consultant
• By night
• Teacher/trainer
• Book Author: Vaadin,
Integration Testing
• Blogger:
https://blog.frankel.ch/
• Speaker
Many kinds of testing
• Unit Testing
• Integration Testing
• End-to-end Testing
• Performance Testing
• Penetration Testing
• Exploratory Testing
• etc.
Their only single goal
• Ensure the Quality of the
production code
• How to check the Quality of
the testing code?
Code coverage
• “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/C
ode_coverage
Measuring Code Coverage
• Check whether a source code
line is executed during a test
• Or Branch Coverage
CC =
Lexecuted
Ltotal
*100
Computing Code
Coverage
• CC: Code Coverage
(in percent)
• Lexecuted: Number of executed
lines of code
• Ltotal: Number of total lines of
code
Java Tools for Code
Coverage
• JaCoCo
• Clover
• Cobertura
• etc.
100% Code Coverage?
“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/unclebobmar
tin/status/55966620509667328
Assert-less testing
@Test
public void add_should_add() {
new Math().add(1, 1);
}
But, where is the
assert?
As long as the Code Coverage is
OK…
Code coverage as a
measure of test quality
• 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 test quality
• Code Coverage lulls you into a
false sense of security…
The problem still stands
• Code coverage cannot ensure
test quality
• Is there another way?
The Cast
Original Source Code
Modified Source Code
a.k.a “The Mutant”
Standard testing
✔Execute Test
Mutation testing
?Execute SAME Test
MUTATION
Mutation testing
✗
✔Execute SAME Test
Execute SAME Test
Mutant
Killed
Mutant Survived
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);
}
Surviving mutant
✔Execute SAME Test
@Test
public void add_should_add() {
new Math().add(1, 1);
}
public class Math {
public int add(int i1, int i2) {
return i1 - i2;
}
}
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);
}
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);
}
Mutation Testing in Java
• PIT is a tool for Mutation
testing
• Available as
• Command-line tool
• Ant target
• Maven plugin
Mutators
• Mutators are patterns applied
to source code to produce
mutations
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 local variable int foo= 42 int 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;
Enough talk!
Drawbacks
• Slow
• Sluggish
• Crawling
• Sulky
• Lethargic
• etc.
Metrics (kind of)
• On joda-money
• mvn clean test-compile
• mvn surefire:test
• Total time: 2.181 s
• mvn pit-test...
• Total time: 48.634 s
Why so slow?
• Analyze test code
• For each class under test
• For each mutator
• Create mutation
• For each mutation
• Run test
• Analyze result
• Aggregate results
Workarounds
• Increase number of threads  
• Set a limited a set of mutators
• Limit scope of target classes
• Limit number of tests
• Limit dependency distance
• Don’t bind to the test phase  
• Use scmMutationCoverage
• Use incremental analysis  
Incremental analysis
• Metadata stored between runs
• During each following run
mutant will not be checked
again, if the last time it:
• timed out, and class has
not changed
• was killed, and neither
class nor test have
changed
• survived, and there are
no new/changed tests
for it
False positives
• Mutation Testing is not 100%
bulletproof
• Might return false positives
• Be cautious!
Pit is imperfect
if (p < 0)
...
// changed condition boundary
// -> survived:
if (p > 0)
...
return 0;
Pit might be dangerous
void reboot() throws IOException {
// removed method call:
checkUserPermissions();
Runtime.getRuntime()
.exec("reboot");
}
Testing is about ROI
• Don’t test to achieve 100%
coverage
• Test because it saves money
in the long run
• Prioritize:
• Business-critical code
• Complex code
Q&A
• https://git.io/vznQK
• http://blog.frankel.ch/
• @nicolas_frankel
• https://leanpub.com/integration
test/

More Related Content

What's hot

An Empirical Study of the Effect of File Editing Patterns on Software Quality
An Empirical Study of the Effect of File Editing Patterns on Software QualityAn Empirical Study of the Effect of File Editing Patterns on Software Quality
An Empirical Study of the Effect of File Editing Patterns on Software Quality
Feng Zhang
 
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
ESEM 2014
 
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
Kim Herzig
 

What's hot (20)

Google, quality and you
Google, quality and youGoogle, quality and you
Google, quality and you
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
 
[Review] Predictive Mutation Testing
[Review] Predictive Mutation Testing[Review] Predictive Mutation Testing
[Review] Predictive Mutation Testing
 
Mutation Testing Workshop at Ericsson, Kista, Sweden
Mutation Testing Workshop at Ericsson, Kista, SwedenMutation Testing Workshop at Ericsson, Kista, Sweden
Mutation Testing Workshop at Ericsson, Kista, Sweden
 
Chap10
Chap10Chap10
Chap10
 
Software testdesign
Software testdesignSoftware testdesign
Software testdesign
 
Unit testing
Unit testingUnit testing
Unit testing
 
An Empirical Study of the Effect of File Editing Patterns on Software Quality
An Empirical Study of the Effect of File Editing Patterns on Software QualityAn Empirical Study of the Effect of File Editing Patterns on Software Quality
An Empirical Study of the Effect of File Editing Patterns on Software Quality
 
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
52 - The Impact of Test Ownership and Team Structure on the Reliability and E...
 
On the Use of Static Analysis to Safeguard Recursive Dependency Resolution
On the Use of Static Analysis to Safeguard Recursive Dependency ResolutionOn the Use of Static Analysis to Safeguard Recursive Dependency Resolution
On the Use of Static Analysis to Safeguard Recursive Dependency Resolution
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
Fabrizio pastore TORACLE-2021 @ESEC/FSE 2021
 
Triantafyllia Voulibasi
Triantafyllia VoulibasiTriantafyllia Voulibasi
Triantafyllia Voulibasi
 
Kobi_H_2018_JustEnoughTesting_02_TestIL_handout
Kobi_H_2018_JustEnoughTesting_02_TestIL_handoutKobi_H_2018_JustEnoughTesting_02_TestIL_handout
Kobi_H_2018_JustEnoughTesting_02_TestIL_handout
 
TMPA-2017: Live testing distributed system fault tolerance with fault injecti...
TMPA-2017: Live testing distributed system fault tolerance with fault injecti...TMPA-2017: Live testing distributed system fault tolerance with fault injecti...
TMPA-2017: Live testing distributed system fault tolerance with fault injecti...
 
Cyclomatic complexity
Cyclomatic complexityCyclomatic complexity
Cyclomatic complexity
 
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
Empirically Detecting False Test Alarms Using Association Rules @ ICSE 2015
 
ATPG flow chart
ATPG flow chart ATPG flow chart
ATPG flow chart
 
OO Metrics
OO MetricsOO Metrics
OO Metrics
 
Introduction to Unit Testing using QUnit
Introduction to Unit Testing using QUnitIntroduction to Unit Testing using QUnit
Introduction to Unit Testing using QUnit
 

Viewers also liked

Get Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP StreamsGet Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP Streams
Davey Shafik
 
Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!
tlrx
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)
Arnauld Loyer
 

Viewers also liked (20)

Caching on the Edge
Caching on the EdgeCaching on the Edge
Caching on the Edge
 
Automation using-phing
Automation using-phingAutomation using-phing
Automation using-phing
 
Techniques d'accélération des pages web
Techniques d'accélération des pages webTechniques d'accélération des pages web
Techniques d'accélération des pages web
 
Diving deep into twig
Diving deep into twigDiving deep into twig
Diving deep into twig
 
Get Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP StreamsGet Soaked - An In Depth Look At PHP Streams
Get Soaked - An In Depth Look At PHP Streams
 
Elastic Searching With PHP
Elastic Searching With PHPElastic Searching With PHP
Elastic Searching With PHP
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)The quest for global design principles (SymfonyLive Berlin 2015)
The quest for global design principles (SymfonyLive Berlin 2015)
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
Top tips my_sql_performance
Top tips my_sql_performanceTop tips my_sql_performance
Top tips my_sql_performance
 
Why elasticsearch rocks!
Why elasticsearch rocks!Why elasticsearch rocks!
Why elasticsearch rocks!
 
Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015Understanding Craftsmanship SwanseaCon2015
Understanding Craftsmanship SwanseaCon2015
 
Writing infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQLWriting infinite scalability web applications with PHP and PostgreSQL
Writing infinite scalability web applications with PHP and PostgreSQL
 
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015Si le tdd est mort alors pratiquons une autopsie mix-it 2015
Si le tdd est mort alors pratiquons une autopsie mix-it 2015
 
L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)L'ABC du BDD (Behavior Driven Development)
L'ABC du BDD (Behavior Driven Development)
 
Performance serveur et apache
Performance serveur et apachePerformance serveur et apache
Performance serveur et apache
 
Behat 3.0 meetup (March)
Behat 3.0 meetup (March)Behat 3.0 meetup (March)
Behat 3.0 meetup (March)
 
TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016TDD with PhpSpec - Lone Star PHP 2016
TDD with PhpSpec - Lone Star PHP 2016
 
The Wonderful World of Symfony Components
The Wonderful World of Symfony ComponentsThe Wonderful World of Symfony Components
The Wonderful World of Symfony Components
 

Similar to I.T.A.K.E Unconference - Mutation testing to the rescue of your tests

CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
Olivera Milenkovic
 

Similar to I.T.A.K.E Unconference - Mutation testing to the rescue of your tests (20)

Cpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp EuropeCpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp Europe
 
Quickly Testing Legacy Cpp Code - ACCU Cambridge 2019
Quickly Testing Legacy Cpp Code - ACCU Cambridge 2019Quickly Testing Legacy Cpp Code - ACCU Cambridge 2019
Quickly Testing Legacy Cpp Code - ACCU Cambridge 2019
 
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
 
Kill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van RijnKill the mutants and test your tests - Roy van Rijn
Kill the mutants and test your tests - Roy van Rijn
 
First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?First steps in testing analytics: Does test code quality matter?
First steps in testing analytics: Does test code quality matter?
 
Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023Getting Started with Test-Driven Development at PHPtek 2023
Getting Started with Test-Driven Development at PHPtek 2023
 
Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 
Полезные метрики покрытия. Практический опыт и немного теории
Полезные метрики покрытия. Практический опыт и немного теорииПолезные метрики покрытия. Практический опыт и немного теории
Полезные метрики покрытия. Практический опыт и немного теории
 
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017Mutation Testing: Leaving the Stone Age. FOSDEM 2017
Mutation Testing: Leaving the Stone Age. FOSDEM 2017
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Introduzione allo Unit Testing
Introduzione allo Unit TestingIntroduzione allo Unit Testing
Introduzione allo Unit Testing
 
A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
Winning the battle against Automated testing
Winning the battle against Automated testingWinning the battle against Automated testing
Winning the battle against Automated testing
 
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
Testing As A Bottleneck - How Testing Slows Down Modern Development Processes...
 
New types of tests for Java projects
New types of tests for Java projectsNew types of tests for Java projects
New types of tests for Java projects
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
 
New types of tests for Java projects
New types of tests for Java projectsNew types of tests for Java projects
New types of tests for Java projects
 

More from Nicolas Fränkel

jLove - A Change-Data-Capture use-case: designing an evergreen cache
jLove - A Change-Data-Capture use-case: designing an evergreen cachejLove - A Change-Data-Capture use-case: designing an evergreen cache
jLove - A Change-Data-Capture use-case: designing an evergreen cache
Nicolas Fränkel
 
OSCONF Hyderabad - Shorten all URLs!
OSCONF Hyderabad - Shorten all URLs!OSCONF Hyderabad - Shorten all URLs!
OSCONF Hyderabad - Shorten all URLs!
Nicolas Fränkel
 
JOnConf - A CDC use-case: designing an Evergreen Cache
JOnConf - A CDC use-case: designing an Evergreen CacheJOnConf - A CDC use-case: designing an Evergreen Cache
JOnConf - A CDC use-case: designing an Evergreen Cache
Nicolas Fränkel
 

More from Nicolas Fränkel (20)

SnowCamp - Adding search to a legacy application
SnowCamp - Adding search to a legacy applicationSnowCamp - Adding search to a legacy application
SnowCamp - Adding search to a legacy application
 
Un CV de dévelopeur toujours a jour
Un CV de dévelopeur toujours a jourUn CV de dévelopeur toujours a jour
Un CV de dévelopeur toujours a jour
 
Zero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with HazelcastZero-downtime deployment on Kubernetes with Hazelcast
Zero-downtime deployment on Kubernetes with Hazelcast
 
jLove - A Change-Data-Capture use-case: designing an evergreen cache
jLove - A Change-Data-Capture use-case: designing an evergreen cachejLove - A Change-Data-Capture use-case: designing an evergreen cache
jLove - A Change-Data-Capture use-case: designing an evergreen cache
 
BigData conference - Introduction to stream processing
BigData conference - Introduction to stream processingBigData conference - Introduction to stream processing
BigData conference - Introduction to stream processing
 
ADDO - Your own Kubernetes controller, not only in Go
ADDO - Your own Kubernetes controller, not only in GoADDO - Your own Kubernetes controller, not only in Go
ADDO - Your own Kubernetes controller, not only in Go
 
TestCon Europe - Mutation Testing to the Rescue of Your Tests
TestCon Europe - Mutation Testing to the Rescue of Your TestsTestCon Europe - Mutation Testing to the Rescue of Your Tests
TestCon Europe - Mutation Testing to the Rescue of Your Tests
 
OSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java application
OSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java applicationOSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java application
OSCONF Jaipur - A Hitchhiker's Tour to Containerizing a Java application
 
GeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cache
GeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cacheGeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cache
GeekcampSG 2020 - A Change-Data-Capture use-case: designing an evergreen cache
 
JavaDay Istanbul - 3 improvements in your microservices architecture
JavaDay Istanbul - 3 improvements in your microservices architectureJavaDay Istanbul - 3 improvements in your microservices architecture
JavaDay Istanbul - 3 improvements in your microservices architecture
 
OSCONF Hyderabad - Shorten all URLs!
OSCONF Hyderabad - Shorten all URLs!OSCONF Hyderabad - Shorten all URLs!
OSCONF Hyderabad - Shorten all URLs!
 
Devclub.lv - Introduction to stream processing
Devclub.lv - Introduction to stream processingDevclub.lv - Introduction to stream processing
Devclub.lv - Introduction to stream processing
 
OSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring Boot
OSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring BootOSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring Boot
OSCONF Koshi - Zero downtime deployment with Kubernetes, Flyway and Spring Boot
 
JOnConf - A CDC use-case: designing an Evergreen Cache
JOnConf - A CDC use-case: designing an Evergreen CacheJOnConf - A CDC use-case: designing an Evergreen Cache
JOnConf - A CDC use-case: designing an Evergreen Cache
 
London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...
London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...
London In-Memory Computing Meetup - A Change-Data-Capture use-case: designing...
 
JUG Tirana - Introduction to data streaming
JUG Tirana - Introduction to data streamingJUG Tirana - Introduction to data streaming
JUG Tirana - Introduction to data streaming
 
Java.IL - Your own Kubernetes controller, not only in Go!
Java.IL - Your own Kubernetes controller, not only in Go!Java.IL - Your own Kubernetes controller, not only in Go!
Java.IL - Your own Kubernetes controller, not only in Go!
 
vJUG - Introduction to data streaming
vJUG - Introduction to data streamingvJUG - Introduction to data streaming
vJUG - Introduction to data streaming
 
London Java Community - An Experiment in Continuous Deployment of JVM applica...
London Java Community - An Experiment in Continuous Deployment of JVM applica...London Java Community - An Experiment in Continuous Deployment of JVM applica...
London Java Community - An Experiment in Continuous Deployment of JVM applica...
 
OSCONF - Your own Kubernetes controller: not only in Go
OSCONF - Your own Kubernetes controller: not only in GoOSCONF - Your own Kubernetes controller: not only in Go
OSCONF - Your own Kubernetes controller: not only in Go
 

Recently uploaded

%+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
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

%+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...
 
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...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
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...
 
%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
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
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
 
%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
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
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
 

I.T.A.K.E Unconference - Mutation testing to the rescue of your tests

  • 1. An event proudly designed by Mutation Testing to the rescue of your tests @nicolas_frankel
  • 2. Me, Myself and I • By day • Hybris consultant • By night • Teacher/trainer • Book Author: Vaadin, Integration Testing • Blogger: https://blog.frankel.ch/ • Speaker
  • 3. Many kinds of testing • Unit Testing • Integration Testing • End-to-end Testing • Performance Testing • Penetration Testing • Exploratory Testing • etc.
  • 4. Their only single goal • Ensure the Quality of the production code • How to check the Quality of the testing code?
  • 5. Code coverage • “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/C ode_coverage
  • 6. Measuring Code Coverage • Check whether a source code line is executed during a test • Or Branch Coverage
  • 7. CC = Lexecuted Ltotal *100 Computing Code Coverage • CC: Code Coverage (in percent) • Lexecuted: Number of executed lines of code • Ltotal: Number of total lines of code
  • 8. Java Tools for Code Coverage • JaCoCo • Clover • Cobertura • etc.
  • 9. 100% Code Coverage? “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/unclebobmar tin/status/55966620509667328
  • 10. Assert-less testing @Test public void add_should_add() { new Math().add(1, 1); } But, where is the assert? As long as the Code Coverage is OK…
  • 11. Code coverage as a measure of test quality • Any metric can be gamed! • Code coverage is a metric… • ⇒ Code coverage can be gamed • On purpose • Or by accident
  • 12. Code coverage as a measure of test quality • Code Coverage lulls you into a false sense of security…
  • 13. The problem still stands • Code coverage cannot ensure test quality • Is there another way?
  • 14. The Cast Original Source Code Modified Source Code a.k.a “The Mutant”
  • 17. Mutation testing ✗ ✔Execute SAME Test Execute SAME Test Mutant Killed Mutant Survived
  • 18. 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); }
  • 19. Surviving mutant ✔Execute SAME Test @Test public void add_should_add() { new Math().add(1, 1); } public class Math { public int add(int i1, int i2) { return i1 - i2; } }
  • 20. 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); }
  • 21. 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); }
  • 22. Mutation Testing in Java • PIT is a tool for Mutation testing • Available as • Command-line tool • Ant target • Maven plugin
  • 23. Mutators • Mutators are patterns applied to source code to produce mutations
  • 24. 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 local variable int foo= 42 int 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;
  • 26. Drawbacks • Slow • Sluggish • Crawling • Sulky • Lethargic • etc.
  • 27. Metrics (kind of) • On joda-money • mvn clean test-compile • mvn surefire:test • Total time: 2.181 s • mvn pit-test... • Total time: 48.634 s
  • 28. Why so slow? • Analyze test code • For each class under test • For each mutator • Create mutation • For each mutation • Run test • Analyze result • Aggregate results
  • 29. Workarounds • Increase number of threads   • Set a limited a set of mutators • Limit scope of target classes • Limit number of tests • Limit dependency distance • Don’t bind to the test phase   • Use scmMutationCoverage • Use incremental analysis  
  • 30. Incremental analysis • Metadata stored between runs • During each following run mutant will not be checked again, if the last time it: • timed out, and class has not changed • was killed, and neither class nor test have changed • survived, and there are no new/changed tests for it
  • 31. False positives • Mutation Testing is not 100% bulletproof • Might return false positives • Be cautious!
  • 32. Pit is imperfect if (p < 0) ... // changed condition boundary // -> survived: if (p > 0) ... return 0;
  • 33. Pit might be dangerous void reboot() throws IOException { // removed method call: checkUserPermissions(); Runtime.getRuntime() .exec("reboot"); }
  • 34. Testing is about ROI • Don’t test to achieve 100% coverage • Test because it saves money in the long run • Prioritize: • Business-critical code • Complex code
  • 35. Q&A • https://git.io/vznQK • http://blog.frankel.ch/ • @nicolas_frankel • https://leanpub.com/integration test/

Editor's Notes

  1. All are integrated in Maven JaCoCo is also integrated into Sonar out-of-the-box
  2. There are also experimental mutators http://pitest.org/quickstart/mutators/
  3. mvn test org.pitest:pitest-maven:mutationCoverage -DexcludedClasses=org.joda.money.TestBigMoney,org.joda.money.TestCurrencyUnit,org.joda.money.TestMoney -DtimestampedReports=false