SlideShare a Scribd company logo
Mutation Testing
THE WAY TO IMPROVE YOUR UNIT TESTS QUALITY
"Quis custodiet ipsos custodes?“
["Who will guard the guards?"]
Why do we need unit tests?
Ensure quality of code
Ensure safety of code changes
How good are our unit tests?
Coverage – 100% ?
Coverage
public class Positive {
public boolean isPositive(int number) {
return number > 0;
}
public boolean isNegative(int number){
return number < 0;
}
}
@Test
public void testPositive()
throws Exception {
assertTrue(Positive.isPositive( 2 ));
}
@Test
public void testNegative()
throws Exception {
assertTrue(Positive.isNegative( -2 ));
}
What if…
public class Positive {
public boolean isPositive(int number) {
return number >= 0;
}
public boolean isNegative(int number) {
return number <= 0;
}
}
@Test
public void testPositive()
throws Exception {
assertTrue(Positive.isPositive( 2 ));
}
@Test
public void testNegative()
throws Exception {
assertTrue(Positive.isNegative( -2 ));
}
100% coverage !
public class Positive {
public boolean isPositive(int number) {
return number >= 0;
}
public boolean isNegative(int number) {
return number <= 0;
}
}
@Test
public void testPositive()
throws Exception {
assertTrue(Positive.isPositive( 2 ));
}
@Test
public void testNegative()
throws Exception {
assertTrue(Positive.isNegative( -2 ));
}
Changing source code should
change test results!
Tests should fail if source code
changes
Changes of source code are
known as … MUTATIONS!
What kind of mutations?
Conditionals ( AND -> OR)
Boundary ( < -> <= )
Void method calls
Increments ( i++, i--)
Negative ( -1*x)
etc
How to kill mutants?
Find mutations
Cover affected cases
mutation score =
number of mutants killed /
total number of mutants
How to find mutants?
Use tools
(e.g. Pitest – www.pitest.org )
Configure
(Maven, Ant, Gradle, Idea plugins)
No need to run every time for whole
codebase
Per package, per class
For altered code
PROs & CONs
Critical code
Find weaknesses in
test suites
TDD
Build time
Development efforts
Not suitable for
integration or blackbox
testing
Good luck!

More Related Content

PPTX
Mutation Testing
PPTX
Mutation Testing - Ruby Edition
PPTX
Property Based Testing
PPTX
Mutation testing
PDF
How to write clean tests
PPTX
Testers guide to unit testing
PDF
STAMP Descartes Presentation
PPTX
Easy practice with if statement and boolean type
Mutation Testing
Mutation Testing - Ruby Edition
Property Based Testing
Mutation testing
How to write clean tests
Testers guide to unit testing
STAMP Descartes Presentation
Easy practice with if statement and boolean type

Similar to Mutation testing - the way to improve unit tests quality (20)

PPTX
Best practices unit testing
PDF
Mutation @ Spotify
PPTX
TestNG vs Junit
PDF
DSR Testing (Part 1)
PDF
Unit testing with JUnit
PPTX
Junit mockito and PowerMock in Java
PDF
Mutation Testing: Start Hunting The Bugs
PDF
JUnit Pioneer
PPTX
130706266060138191
PPT
Test Driven Development
PDF
Example First / A Sane Test-Driven Approach to Programming
PPT
Security Testing
PPTX
Mutation Testing: Testing your tests
PDF
We Are All Testers Now: The Testing Pyramid and Front-End Development
PPTX
Qunit Java script Un
PDF
The Impact of Test Case Summaries on Bug Fixing Performance: An Empirical Inv...
PDF
Stamp breizhcamp 2019
PDF
Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...
PDF
What NOT to test in your project
PPTX
Navigating the xDD Alphabet Soup
Best practices unit testing
Mutation @ Spotify
TestNG vs Junit
DSR Testing (Part 1)
Unit testing with JUnit
Junit mockito and PowerMock in Java
Mutation Testing: Start Hunting The Bugs
JUnit Pioneer
130706266060138191
Test Driven Development
Example First / A Sane Test-Driven Approach to Programming
Security Testing
Mutation Testing: Testing your tests
We Are All Testers Now: The Testing Pyramid and Front-End Development
Qunit Java script Un
The Impact of Test Case Summaries on Bug Fixing Performance: An Empirical Inv...
Stamp breizhcamp 2019
Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...
What NOT to test in your project
Navigating the xDD Alphabet Soup
Ad

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
assetexplorer- product-overview - presentation
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
System and Network Administraation Chapter 3
PDF
Digital Strategies for Manufacturing Companies
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Cost to Outsource Software Development in 2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Upgrade and Innovation Strategies for SAP ERP Customers
assetexplorer- product-overview - presentation
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Navsoft: AI-Powered Business Solutions & Custom Software Development
System and Network Administraation Chapter 3
Digital Strategies for Manufacturing Companies
wealthsignaloriginal-com-DS-text-... (1).pdf
L1 - Introduction to python Backend.pptx
Cost to Outsource Software Development in 2025
Reimagine Home Health with the Power of Agentic AI​
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Digital Systems & Binary Numbers (comprehensive )
Odoo Companies in India – Driving Business Transformation.pdf
Understanding Forklifts - TECH EHS Solution
Design an Analysis of Algorithms I-SECS-1021-03
Ad

Mutation testing - the way to improve unit tests quality

  • 1. Mutation Testing THE WAY TO IMPROVE YOUR UNIT TESTS QUALITY "Quis custodiet ipsos custodes?“ ["Who will guard the guards?"]
  • 2. Why do we need unit tests? Ensure quality of code Ensure safety of code changes
  • 3. How good are our unit tests? Coverage – 100% ?
  • 4. Coverage public class Positive { public boolean isPositive(int number) { return number > 0; } public boolean isNegative(int number){ return number < 0; } } @Test public void testPositive() throws Exception { assertTrue(Positive.isPositive( 2 )); } @Test public void testNegative() throws Exception { assertTrue(Positive.isNegative( -2 )); }
  • 5. What if… public class Positive { public boolean isPositive(int number) { return number >= 0; } public boolean isNegative(int number) { return number <= 0; } } @Test public void testPositive() throws Exception { assertTrue(Positive.isPositive( 2 )); } @Test public void testNegative() throws Exception { assertTrue(Positive.isNegative( -2 )); }
  • 6. 100% coverage ! public class Positive { public boolean isPositive(int number) { return number >= 0; } public boolean isNegative(int number) { return number <= 0; } } @Test public void testPositive() throws Exception { assertTrue(Positive.isPositive( 2 )); } @Test public void testNegative() throws Exception { assertTrue(Positive.isNegative( -2 )); }
  • 7. Changing source code should change test results! Tests should fail if source code changes Changes of source code are known as … MUTATIONS!
  • 8. What kind of mutations? Conditionals ( AND -> OR) Boundary ( < -> <= ) Void method calls Increments ( i++, i--) Negative ( -1*x) etc
  • 9. How to kill mutants? Find mutations Cover affected cases mutation score = number of mutants killed / total number of mutants
  • 10. How to find mutants? Use tools (e.g. Pitest – www.pitest.org ) Configure (Maven, Ant, Gradle, Idea plugins) No need to run every time for whole codebase Per package, per class For altered code
  • 11. PROs & CONs Critical code Find weaknesses in test suites TDD Build time Development efforts Not suitable for integration or blackbox testing