SlideShare a Scribd company logo
© Computas AS 11.03.14
Mutation Testing with PIT
Filip van Laenen
Booster 2014
2014-03-13
2 © Computas AS 11.03.14
Agenda
• Basics of mutation testing
• Relation to other testing techniques
• Example
• Mutation testing techniques
• Mutation testing tools
• Personal experiences and recommendations
3 © Computas AS 11.03.14
Basics of
Mutation Testing
4 © Computas AS 11.03.14
Mutation Testing in a Nutshell
Seeking The Summoner @ The Daily WTF
http://thedailywtf.com/Articles/Seeking-The-Summoner.aspx
5 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
6 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
7 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
• Unit tests guard the source code
• But who guards the guardians?
• Do the unit tests cover all source code?
• Lines?
• Branches?
• Paths?
• Do the unit tests test the right things?
Mutation testing tests the tests!
8 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
9 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
10 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
11 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
12 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
13 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
14 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
int max(int a, int b) {
return (a < b) ? b : a;
}
int max(int a, int b) {
return (a <= b) ? b : a;
}
15 © Computas AS 11.03.14
Mutation Testing in a Nutshell (cont'd)
“
16 © Computas AS 11.03.14
Does Mutation Testing Work?
In practice, if the software contains a
fault, there will usually be a set of
mutants that can only be killed by a test
case that also detects that fault.
Geist et. al., “Estimation and Enhancement of Real-time
Software Reliability through Mutation Analysis,” 1992
“
17 © Computas AS 11.03.14
Does Mutation Testing Work? (cont'd)
Complex faults are coupled to simple
faults in such a way that a test data set
that detects all simple faults in a program
will detect most complex faults.
K. Wah, “Fault Coupling in Finite Bijective Functions,”
1995
18 © Computas AS 11.03.14
Does Mutation Testing Work? (cont'd)
• “Generated mutants are similar to real faults.”
• Andrews, Briand, Labiche, ICSE 2005
• “Mutation testing is more powerful than
statement or branch coverage.”
• Walsh, Ph.D. Thesis, State University of New York at
Binghampton, 1985
• “Mutation testing is superior to data flow
coverage criteria.”
• Frankl, Weiss, Hu, Journal of Systems and Software,
1997
19 © Computas AS 11.03.14
Relation to Other
Testing Techniques
20 © Computas AS 11.03.14
Relation to Other Testing Techniques
• Unit tests
• Test-Driven Development (TDD)
• Test coverage
• Static code analysis
• Fuzz testing
21 © Computas AS 11.03.14
Relation to Other Testing Techniques
22 © Computas AS 11.03.14
Is Mutation Testing New?
• R. Lipton, “Fault Diagnosis of Computer
Programs,” 1971
• R. Lipton et. al., “Hints on Test Data Selection:
Help for the Practicing Programmer,” 1978
• Historical obstacles:
• No unit testing
• No TDD
• Inefficient implementation
• Hence time-consuming
• No integration with IDEs
23 © Computas AS 11.03.14
Practical Example
of Mutation Testing
24 © Computas AS 11.03.14
Code Along…
https://github.com/computas-fvl/booster2014
git clone 
https://github.com/computas-fvl/booster2014.git
mvn clean site:site 
org.pitest:pitest-maven:mutationCoverage
25 © Computas AS 11.03.14
Mutation Testing
Techniques
26 © Computas AS 11.03.14
Mutation Testing Techniques
• Three aspects:
• Mutation injection
• Mutation types
• Unit test selection per mutant
• Key properties:
• Efficiency
• Performance
27 © Computas AS 11.03.14
Mutation Injection
• Source code mutation
• Binary code mutation
• Caveats:
• De-mutation
• Compilation errors
• Invalid binary code
28 © Computas AS 11.03.14
Mutation Types
• Some mutations never change behaviour
• Constants reused by unit tests
• Log messages
• Some mutations can change behaviour
• Switching between < and ≠
• Switching between < and ≤
• Some mutations always change behaviour
• Switching between < and ≥
29 © Computas AS 11.03.14
Mutation Types (cont'd)
int max(int a, int b) {
return (a < b) ? b : a;
}
int max(int a, int b) {
return (a <= b) ? b : a;
}
int max(int a, int b) {
return (a >= b) ? b : a;
}
30 © Computas AS 11.03.14
Mutation Types (cont'd)
for (int i = 0; i < 10; i++) …
for (int i = 0; i != 10; i++) …
for (int i = 0; i >= 10; i++) …
31 © Computas AS 11.03.14
Mutation Types Guaranteed to Change
Behaviour
• Negation of the comparison
• Switching between = and ≠
• Switching between < and ≥
• Switching between > and ≤
• Negation of boolean conditions
• Adding a ¬, ! or ~
• Shortcutting boolean conditions
• Replacement with True or False
*
32 © Computas AS 11.03.14
Unit Test Selection
• Goal: find the unit test that “kills” the mutant
• Selection aids:
• Hints
• Name/package matching
• Code coverage tools
• Automatic learning
• Other heuristics
33 © Computas AS 11.03.14
Unit Test Selection (cont'd)
• System:
• 50 classes
• 20 unit tests per class
• 1 ms per unit test
• Unit testing time: 50 × 20 × 1ms = 1s
• 10 mutants per class:
• Brute-force: 10 × 50 × 1s = 6m 20s
• Educated: 10 × 50 × 20 × 1ms = 10s
34 © Computas AS 11.03.14
Unit Test Selection (cont'd)
• System:
• 500 classes
• 20 unit tests per class
• 1 ms per unit test
• Unit testing time: 500 × 20 × 1ms = 10s
• 10 mutants per class:
• Brute-force: 10 × 500 × 10s = 13h 53m 20s
• Educated: 10 × 500 × 20 × 1ms = 1m 40s
35 © Computas AS 11.03.14
Complexity
• f: Number of function points
• φ: Number of function points per class, ≥ 1
• τ: Number of unit tests per function point, ≥ 1
• μ: Number of mutants per function point, ≥ 1
• Brute-force: (f × τ) × (f × μ) = τ × μ × f²
• Educated force: τ × μ × φ × f
• Ideal: τ × μ × f
36 © Computas AS 11.03.14
Complexity (cont'd)
• c: Number of classes
• φ: Number of function points per class, ≥ 1
• τ: Number of unit tests per function point, ≥ 1
• μ: Number of mutants per function point, ≥ 1
• Brute-force: (f × τ) × (f × μ) = τ × μ × φ² × c²
• Educated force: τ × μ × φ² × c
• Ideal: τ × μ × φ × c
37 © Computas AS 11.03.14
Loops
for (int i = 0; i < 10; i++) …
for (int i = 0; i < 10; i--) …
38 © Computas AS 11.03.14
Infinite Loops
• Terminate mutants that take too long to run
• What's “too long”?
• Ruins the performance
• Can be hard to predict
39 © Computas AS 11.03.14
Other Problems
• Recursion:
• Stack overflows
• Out of memory exceptions
• Syntax errors
• Segmentation faults
40 © Computas AS 11.03.14
Mutation Testing
Tools
41 © Computas AS 11.03.14
Mutation Testing Tools
• Java:
• PIT
• Jester (Nester, Pester)
• Jumble
• Ruby:
• Mutant
• Heckle
• C#:
• NinjaTurtles
42 © Computas AS 11.03.14
PIT
• Java
• Junit & TestNG
• Maven or command-line
• Operates on byte code
• Large set of mutators
• Also possibly equivalent mutators available
• Highly configurable
• Sensible defaults
• http://pitest.org/
43 © Computas AS 11.03.14
PIT Mutators
• Conditionals Boundary
• Negate Conditionals
• Remove Conditionals*
• Math
• Increments
• Invert Negatives
• Inline Constant*
• Return Values
• Void Method Calls
• Non Void Method Calls*
• Constructor Calls*
44 © Computas AS 11.03.14
PIT Sample Report
45 © Computas AS 11.03.14
Jester
• Java
• JUnit
• Usually run from the command-line
• Grester for Maven2
• Operates on source code
• Runs all unit tests on all classes
• Reporting and documentation could be better
• http://jester.sourceforge.net/
• http://sourceforge.net/projects/grester/
46 © Computas AS 11.03.14
Jester Sample Report Overview
47 © Computas AS 11.03.14
Jester Sample Detailed Report
48 © Computas AS 11.03.14
Pester and Nester
• Pester
• Jester for Python
• PyUnit
• Nester
• Port of Jester for C#
• NUnit
• Integrated with Visual Studio
• But outdated…
• http://nester.sourceforge.net/
49 © Computas AS 11.03.14
Nester Sample Report
50 © Computas AS 11.03.14
Jumble
• Java
• JUnit
• Run from the command-line
• Operates on byte code
• Runs unit tests on a class
• Reporting and documentation could be better
• Claims to be faster than Jester
• http://jumble.sourceforge.net/index.html
51 © Computas AS 11.03.14
Jumble Sample Report
Mutating Foo
Tests: FooTest
Mutation points = 12, unit test time limit 2.02s
..
M FAIL: Foo:31: negated conditional
M FAIL: Foo:33: negated conditional
M FAIL: Foo:34: - -> +
M FAIL: Foo:35: negated conditional
......
Score: 67%
52 © Computas AS 11.03.14
Mutant
• Ruby 1.9 and 2.0
• rspec2
• Usually run from the command-line
• Good to-the-point reporting
• Good performance
• OK documentation
• Active project
• https://github.com/mbj/mutant
53 © Computas AS 11.03.14
Heckle
• Ruby 1.8
• Doesn't work on Ruby 1.9
• Test::Unit and rSpec
• Usually run from the command-line
• Runs a set of unit tests on a class or a method
• Good to-the-point reporting
• Good performance
• Virtually no documentation
• http://rubyforge.org/projects/seattlerb/
• http://docs.seattlerb.org/heckle/
54 © Computas AS 11.03.14
Heckle Mutations
• Booleans
• Numbers
• Strings
• Symbols
• Ranges
• Regexes
• Branches (if, while, unless, until)
55 © Computas AS 11.03.14
NinjaTurtles
• .Net:
• C#
• Visual Basic/VB.NET
• Any other .NET language code
• Doesn't seem much alive
• http://www.mutation-testing.net/
56 © Computas AS 11.03.14
NinjaTurtles Mutations
• Sequence point deletion
• Arithmetic operator substitution (*, /, +, -, %)
• Bitwise operator substitution (&, |, ^)
• Branch substituion (condition, always and never
branch)
• Conditional boundary substition (< and <=, >
and >=)
• Substitution of reads from variables,
parameters and fields of the same type
• Substitution of writes to variables of the same
type
57 © Computas AS 11.03.14
Personal Experiences
and Recommendations
58 © Computas AS 11.03.14
Experiences and Recommendations
• Use mutation testing from day 1
• Start on a small code base
• Keep number of unit tests per class low
• Have small classes
• Select a good tool
• Configurable
• Flexible
• One that can output the mutant
59 © Computas AS 11.03.14
Experiences and Recommendations
(cont'd)
• Believe the tool
• Or try to proof that the tool is wrong
• Fix the problem
• Don't turn mutation testing off
• Embrace the “more than 100%” test coverage
• Path coverage
• Less code
• More unit tests
• More intelligent unit tests
60 © Computas AS 11.03.14
Improvements
61 © Computas AS 11.03.14
Improvements
• Integration with more unit testing frameworks
• Better unit test–source code mapping
• Better heuristics
• Parallellisation
• Better reporting
• IDE integration
• Building tool integration
62 © Computas AS 11.03.14
Questions?
Computas AS
Lysaker Torg 45, pb 482
N-1327 Lysaker
NORWAY
Tel +47-67 83 10 00
Fax +47-67 83 10 01
Org.nr: NO 986 352 325 MVA
www.computas.com
Contact:
fvl@computas.com @filipvanlaenen

More Related Content

PDF
Mutation Testing
ESUG
 
PPTX
Kill the mutants and test your tests - Roy van Rijn
NLJUG
 
PDF
Kill the mutants - A better way to test your tests
Roy van Rijn
 
PDF
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
Tarin Gamberini
 
PPTX
Mutation Testing
10Pines
 
PDF
MUTANTS KILLER - PIT: state of the art of mutation testing system
Tarin Gamberini
 
PDF
Mutation testing in Java
Wojciech Langiewicz
 
PPTX
GeeCON - Improve your tests with Mutation Testing
Nicolas Fränkel
 
Mutation Testing
ESUG
 
Kill the mutants and test your tests - Roy van Rijn
NLJUG
 
Kill the mutants - A better way to test your tests
Roy van Rijn
 
MUTANTS KILLER (Revised) - PIT: state of the art of mutation testing system
Tarin Gamberini
 
Mutation Testing
10Pines
 
MUTANTS KILLER - PIT: state of the art of mutation testing system
Tarin Gamberini
 
Mutation testing in Java
Wojciech Langiewicz
 
GeeCON - Improve your tests with Mutation Testing
Nicolas Fränkel
 

What's hot (18)

PDF
C++ Unit Test with Google Testing Framework
Humberto Marchezi
 
PDF
An introduction to Google test framework
Abner Chih Yi Huang
 
PPT
Unit testing with java
Dinuka Malalanayake
 
ODP
Automated testing in Python and beyond
dn
 
PPT
20111018 boost and gtest
Will Shen
 
KEY
Unit Test Your Database
David Wheeler
 
PPT
3 j unit
kishoregali
 
PDF
Sample Chapter of Practical Unit Testing with TestNG and Mockito
Tomek Kaczanowski
 
PDF
JUnit & Mockito, first steps
Renato Primavera
 
PDF
Test driven development
christoforosnalmpantis
 
PDF
GeeCON 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
PPT
Google mock for dummies
Harry Potter
 
PDF
Confitura 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
PPSX
Junit
FAROOK Samath
 
ODP
Advanced junit and mockito
Mathieu Carbou
 
PPT
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
ODT
Testing in-python-and-pytest-framework
Arulalan T
 
PDF
TDD in Python With Pytest
Eddy Reyes
 
C++ Unit Test with Google Testing Framework
Humberto Marchezi
 
An introduction to Google test framework
Abner Chih Yi Huang
 
Unit testing with java
Dinuka Malalanayake
 
Automated testing in Python and beyond
dn
 
20111018 boost and gtest
Will Shen
 
Unit Test Your Database
David Wheeler
 
3 j unit
kishoregali
 
Sample Chapter of Practical Unit Testing with TestNG and Mockito
Tomek Kaczanowski
 
JUnit & Mockito, first steps
Renato Primavera
 
Test driven development
christoforosnalmpantis
 
GeeCON 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
Google mock for dummies
Harry Potter
 
Confitura 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
Advanced junit and mockito
Mathieu Carbou
 
Stopping the Rot - Putting Legacy C++ Under Test
Seb Rose
 
Testing in-python-and-pytest-framework
Arulalan T
 
TDD in Python With Pytest
Eddy Reyes
 
Ad

Viewers also liked (19)

PDF
أخطاء برمجية | programming errors
nawal saad
 
PDF
Igor Popov: Mutation Testing at I T.A.K.E. Unconference 2015
Mozaic Works
 
PPTX
Mutation testing
Raúl Ávila
 
PPT
تحليل النظم
Kohinour Osman
 
PPTX
Re charge the interview
Claudio De La Parra
 
PDF
Doctor of Philosophy
rashidw
 
PDF
Costituciones y pacto social
Giovany2015
 
PDF
Guide aides financieres renovation habitat - juillet -2016
Isocell France
 
PPSX
שנה טובה מישראל נגלית לעין
israelalbum_ybz
 
PPTX
Introduction to the Global Crop Diversity Trust
Luigi Guarino
 
DOCX
5 d nl11 unidad2 3
Lab2computacion2
 
PDF
Preguntas 3-encu-clau
Diego Solano
 
DOCX
Brian Ramirez-Letter of Recommendation
Brian Ramirez
 
PPTX
АТОЛ. Презентация 1
MoySklad
 
PDF
Gramática - Advérbio
Mentor Concursos
 
PDF
The Human Brain
annhmoore
 
PDF
Simon White Showreel
Simon White
 
PDF
2015 05 heimdall-joint-brochure-v03
Mark Repton
 
PPTX
Maledivy 2
PetkaHuskova
 
أخطاء برمجية | programming errors
nawal saad
 
Igor Popov: Mutation Testing at I T.A.K.E. Unconference 2015
Mozaic Works
 
Mutation testing
Raúl Ávila
 
تحليل النظم
Kohinour Osman
 
Re charge the interview
Claudio De La Parra
 
Doctor of Philosophy
rashidw
 
Costituciones y pacto social
Giovany2015
 
Guide aides financieres renovation habitat - juillet -2016
Isocell France
 
שנה טובה מישראל נגלית לעין
israelalbum_ybz
 
Introduction to the Global Crop Diversity Trust
Luigi Guarino
 
5 d nl11 unidad2 3
Lab2computacion2
 
Preguntas 3-encu-clau
Diego Solano
 
Brian Ramirez-Letter of Recommendation
Brian Ramirez
 
АТОЛ. Презентация 1
MoySklad
 
Gramática - Advérbio
Mentor Concursos
 
The Human Brain
annhmoore
 
Simon White Showreel
Simon White
 
2015 05 heimdall-joint-brochure-v03
Mark Repton
 
Maledivy 2
PetkaHuskova
 
Ad

Similar to Mutation Testing with PIT (Booster 2014, 2014-MAR-13) (20)

PDF
Oop 2015 – Mutation Testing
Filip Van Laenen
 
PDF
How good are your tests?
Noam Shaish
 
PDF
Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012
TEST Huddle
 
PDF
SSBSE 2020 keynote
Shiva Nejati
 
PDF
Shift-Left Testing: QA in a DevOps World by David Laulusa
QA or the Highway
 
PDF
Automatic Test Pattern Generation (Testing of VLSI Design)
Usha Mehta
 
PPTX
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
PPTX
Performance Issue? Machine Learning to the rescue!
Maarten Smeets
 
PPTX
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Wolfgang Grieskamp
 
PDF
Seven deadly sins of ElasticSearch Benchmarking
Fan Robbin
 
PPTX
Distributed Model Validation with Epsilon
Sina Madani
 
PPTX
Avoiding test hell
Yun Ki Lee
 
PDF
Performance Testing Java Applications
C4Media
 
PDF
Testing of Cyber-Physical Systems: Diversity-driven Strategies
Lionel Briand
 
PPT
Chapter 14 software testing techniques
SHREEHARI WADAWADAGI
 
PDF
TMPA-2017: Live testing distributed system fault tolerance with fault injecti...
Iosif Itkin
 
PPTX
NIO-ICSE2022.pptx
DavidWei89
 
PPTX
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
Claire Le Goues
 
PDF
Mutation Testing.pdf
Keir Bowden
 
Oop 2015 – Mutation Testing
Filip Van Laenen
 
How good are your tests?
Noam Shaish
 
Mike Bartley - Innovations for Testing Parallel Software - EuroSTAR 2012
TEST Huddle
 
SSBSE 2020 keynote
Shiva Nejati
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
QA or the Highway
 
Automatic Test Pattern Generation (Testing of VLSI Design)
Usha Mehta
 
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
Performance Issue? Machine Learning to the rescue!
Maarten Smeets
 
Model-Based Testing: Theory and Practice. Keynote @ MoTiP (ISSRE) 2012.
Wolfgang Grieskamp
 
Seven deadly sins of ElasticSearch Benchmarking
Fan Robbin
 
Distributed Model Validation with Epsilon
Sina Madani
 
Avoiding test hell
Yun Ki Lee
 
Performance Testing Java Applications
C4Media
 
Testing of Cyber-Physical Systems: Diversity-driven Strategies
Lionel Briand
 
Chapter 14 software testing techniques
SHREEHARI WADAWADAGI
 
TMPA-2017: Live testing distributed system fault tolerance with fault injecti...
Iosif Itkin
 
NIO-ICSE2022.pptx
DavidWei89
 
It Does What You Say, Not What You Mean: Lessons From A Decade of Program Repair
Claire Le Goues
 
Mutation Testing.pdf
Keir Bowden
 

More from Filip Van Laenen (18)

PDF
Drawing for IT Architects
Filip Van Laenen
 
PDF
How JSR 385 could have saved the Mars Climate Orbiter
Filip Van Laenen
 
PDF
How JSR-385 Could Have Saved the Mars Climate Orbiter
Filip Van Laenen
 
PDF
Clouds with Trenches and Sharp Edges
Filip Van Laenen
 
PDF
Become an SVG Architect, not a PowerPoint Architect
Filip Van Laenen
 
PDF
Dial M for Mutation
Filip Van Laenen
 
PDF
Mutasjonstesting – Lag bugs for å få bedre kode
Filip Van Laenen
 
PDF
Hvem kommer til å vinne kommunevalget?
Filip Van Laenen
 
PDF
Five Inconvenient Truths about REST
Filip Van Laenen
 
PDF
How Free Data Can Drive Some of the Monkey Business Out of Political Journali...
Filip Van Laenen
 
PDF
#NoEstimates – Smidig 2014
Filip Van Laenen
 
PDF
#NoEstimates – Javazone 2014
Filip Van Laenen
 
PDF
Tre ubeleilige sannheter om REST
Filip Van Laenen
 
PDF
What Architects Really Do
Filip Van Laenen
 
PDF
Hvorfor stole på e-valg 2011/13?
Filip Van Laenen
 
PDF
Mutation testing (OOP 2012, 2012-JAN-24)
Filip Van Laenen
 
PDF
SVG (Devoxx 2011, 2011-NOV-14)
Filip Van Laenen
 
PDF
SVG (Framsia, 27-SEP-2011)
Filip Van Laenen
 
Drawing for IT Architects
Filip Van Laenen
 
How JSR 385 could have saved the Mars Climate Orbiter
Filip Van Laenen
 
How JSR-385 Could Have Saved the Mars Climate Orbiter
Filip Van Laenen
 
Clouds with Trenches and Sharp Edges
Filip Van Laenen
 
Become an SVG Architect, not a PowerPoint Architect
Filip Van Laenen
 
Dial M for Mutation
Filip Van Laenen
 
Mutasjonstesting – Lag bugs for å få bedre kode
Filip Van Laenen
 
Hvem kommer til å vinne kommunevalget?
Filip Van Laenen
 
Five Inconvenient Truths about REST
Filip Van Laenen
 
How Free Data Can Drive Some of the Monkey Business Out of Political Journali...
Filip Van Laenen
 
#NoEstimates – Smidig 2014
Filip Van Laenen
 
#NoEstimates – Javazone 2014
Filip Van Laenen
 
Tre ubeleilige sannheter om REST
Filip Van Laenen
 
What Architects Really Do
Filip Van Laenen
 
Hvorfor stole på e-valg 2011/13?
Filip Van Laenen
 
Mutation testing (OOP 2012, 2012-JAN-24)
Filip Van Laenen
 
SVG (Devoxx 2011, 2011-NOV-14)
Filip Van Laenen
 
SVG (Framsia, 27-SEP-2011)
Filip Van Laenen
 

Recently uploaded (20)

PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
The Future of Artificial Intelligence (AI)
Mukul
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Doc9.....................................
SofiaCollazos
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 

Mutation Testing with PIT (Booster 2014, 2014-MAR-13)

  • 1. © Computas AS 11.03.14 Mutation Testing with PIT Filip van Laenen Booster 2014 2014-03-13
  • 2. 2 © Computas AS 11.03.14 Agenda • Basics of mutation testing • Relation to other testing techniques • Example • Mutation testing techniques • Mutation testing tools • Personal experiences and recommendations
  • 3. 3 © Computas AS 11.03.14 Basics of Mutation Testing
  • 4. 4 © Computas AS 11.03.14 Mutation Testing in a Nutshell Seeking The Summoner @ The Daily WTF http://thedailywtf.com/Articles/Seeking-The-Summoner.aspx
  • 5. 5 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 6. 6 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 7. 7 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd) • Unit tests guard the source code • But who guards the guardians? • Do the unit tests cover all source code? • Lines? • Branches? • Paths? • Do the unit tests test the right things? Mutation testing tests the tests!
  • 8. 8 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 9. 9 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 10. 10 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 11. 11 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 12. 12 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 13. 13 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 14. 14 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd) int max(int a, int b) { return (a < b) ? b : a; } int max(int a, int b) { return (a <= b) ? b : a; }
  • 15. 15 © Computas AS 11.03.14 Mutation Testing in a Nutshell (cont'd)
  • 16. “ 16 © Computas AS 11.03.14 Does Mutation Testing Work? In practice, if the software contains a fault, there will usually be a set of mutants that can only be killed by a test case that also detects that fault. Geist et. al., “Estimation and Enhancement of Real-time Software Reliability through Mutation Analysis,” 1992
  • 17. “ 17 © Computas AS 11.03.14 Does Mutation Testing Work? (cont'd) Complex faults are coupled to simple faults in such a way that a test data set that detects all simple faults in a program will detect most complex faults. K. Wah, “Fault Coupling in Finite Bijective Functions,” 1995
  • 18. 18 © Computas AS 11.03.14 Does Mutation Testing Work? (cont'd) • “Generated mutants are similar to real faults.” • Andrews, Briand, Labiche, ICSE 2005 • “Mutation testing is more powerful than statement or branch coverage.” • Walsh, Ph.D. Thesis, State University of New York at Binghampton, 1985 • “Mutation testing is superior to data flow coverage criteria.” • Frankl, Weiss, Hu, Journal of Systems and Software, 1997
  • 19. 19 © Computas AS 11.03.14 Relation to Other Testing Techniques
  • 20. 20 © Computas AS 11.03.14 Relation to Other Testing Techniques • Unit tests • Test-Driven Development (TDD) • Test coverage • Static code analysis • Fuzz testing
  • 21. 21 © Computas AS 11.03.14 Relation to Other Testing Techniques
  • 22. 22 © Computas AS 11.03.14 Is Mutation Testing New? • R. Lipton, “Fault Diagnosis of Computer Programs,” 1971 • R. Lipton et. al., “Hints on Test Data Selection: Help for the Practicing Programmer,” 1978 • Historical obstacles: • No unit testing • No TDD • Inefficient implementation • Hence time-consuming • No integration with IDEs
  • 23. 23 © Computas AS 11.03.14 Practical Example of Mutation Testing
  • 24. 24 © Computas AS 11.03.14 Code Along… https://github.com/computas-fvl/booster2014 git clone https://github.com/computas-fvl/booster2014.git mvn clean site:site org.pitest:pitest-maven:mutationCoverage
  • 25. 25 © Computas AS 11.03.14 Mutation Testing Techniques
  • 26. 26 © Computas AS 11.03.14 Mutation Testing Techniques • Three aspects: • Mutation injection • Mutation types • Unit test selection per mutant • Key properties: • Efficiency • Performance
  • 27. 27 © Computas AS 11.03.14 Mutation Injection • Source code mutation • Binary code mutation • Caveats: • De-mutation • Compilation errors • Invalid binary code
  • 28. 28 © Computas AS 11.03.14 Mutation Types • Some mutations never change behaviour • Constants reused by unit tests • Log messages • Some mutations can change behaviour • Switching between < and ≠ • Switching between < and ≤ • Some mutations always change behaviour • Switching between < and ≥
  • 29. 29 © Computas AS 11.03.14 Mutation Types (cont'd) int max(int a, int b) { return (a < b) ? b : a; } int max(int a, int b) { return (a <= b) ? b : a; } int max(int a, int b) { return (a >= b) ? b : a; }
  • 30. 30 © Computas AS 11.03.14 Mutation Types (cont'd) for (int i = 0; i < 10; i++) … for (int i = 0; i != 10; i++) … for (int i = 0; i >= 10; i++) …
  • 31. 31 © Computas AS 11.03.14 Mutation Types Guaranteed to Change Behaviour • Negation of the comparison • Switching between = and ≠ • Switching between < and ≥ • Switching between > and ≤ • Negation of boolean conditions • Adding a ¬, ! or ~ • Shortcutting boolean conditions • Replacement with True or False *
  • 32. 32 © Computas AS 11.03.14 Unit Test Selection • Goal: find the unit test that “kills” the mutant • Selection aids: • Hints • Name/package matching • Code coverage tools • Automatic learning • Other heuristics
  • 33. 33 © Computas AS 11.03.14 Unit Test Selection (cont'd) • System: • 50 classes • 20 unit tests per class • 1 ms per unit test • Unit testing time: 50 × 20 × 1ms = 1s • 10 mutants per class: • Brute-force: 10 × 50 × 1s = 6m 20s • Educated: 10 × 50 × 20 × 1ms = 10s
  • 34. 34 © Computas AS 11.03.14 Unit Test Selection (cont'd) • System: • 500 classes • 20 unit tests per class • 1 ms per unit test • Unit testing time: 500 × 20 × 1ms = 10s • 10 mutants per class: • Brute-force: 10 × 500 × 10s = 13h 53m 20s • Educated: 10 × 500 × 20 × 1ms = 1m 40s
  • 35. 35 © Computas AS 11.03.14 Complexity • f: Number of function points • φ: Number of function points per class, ≥ 1 • τ: Number of unit tests per function point, ≥ 1 • μ: Number of mutants per function point, ≥ 1 • Brute-force: (f × τ) × (f × μ) = τ × μ × f² • Educated force: τ × μ × φ × f • Ideal: τ × μ × f
  • 36. 36 © Computas AS 11.03.14 Complexity (cont'd) • c: Number of classes • φ: Number of function points per class, ≥ 1 • τ: Number of unit tests per function point, ≥ 1 • μ: Number of mutants per function point, ≥ 1 • Brute-force: (f × τ) × (f × μ) = τ × μ × φ² × c² • Educated force: τ × μ × φ² × c • Ideal: τ × μ × φ × c
  • 37. 37 © Computas AS 11.03.14 Loops for (int i = 0; i < 10; i++) … for (int i = 0; i < 10; i--) …
  • 38. 38 © Computas AS 11.03.14 Infinite Loops • Terminate mutants that take too long to run • What's “too long”? • Ruins the performance • Can be hard to predict
  • 39. 39 © Computas AS 11.03.14 Other Problems • Recursion: • Stack overflows • Out of memory exceptions • Syntax errors • Segmentation faults
  • 40. 40 © Computas AS 11.03.14 Mutation Testing Tools
  • 41. 41 © Computas AS 11.03.14 Mutation Testing Tools • Java: • PIT • Jester (Nester, Pester) • Jumble • Ruby: • Mutant • Heckle • C#: • NinjaTurtles
  • 42. 42 © Computas AS 11.03.14 PIT • Java • Junit & TestNG • Maven or command-line • Operates on byte code • Large set of mutators • Also possibly equivalent mutators available • Highly configurable • Sensible defaults • http://pitest.org/
  • 43. 43 © Computas AS 11.03.14 PIT Mutators • Conditionals Boundary • Negate Conditionals • Remove Conditionals* • Math • Increments • Invert Negatives • Inline Constant* • Return Values • Void Method Calls • Non Void Method Calls* • Constructor Calls*
  • 44. 44 © Computas AS 11.03.14 PIT Sample Report
  • 45. 45 © Computas AS 11.03.14 Jester • Java • JUnit • Usually run from the command-line • Grester for Maven2 • Operates on source code • Runs all unit tests on all classes • Reporting and documentation could be better • http://jester.sourceforge.net/ • http://sourceforge.net/projects/grester/
  • 46. 46 © Computas AS 11.03.14 Jester Sample Report Overview
  • 47. 47 © Computas AS 11.03.14 Jester Sample Detailed Report
  • 48. 48 © Computas AS 11.03.14 Pester and Nester • Pester • Jester for Python • PyUnit • Nester • Port of Jester for C# • NUnit • Integrated with Visual Studio • But outdated… • http://nester.sourceforge.net/
  • 49. 49 © Computas AS 11.03.14 Nester Sample Report
  • 50. 50 © Computas AS 11.03.14 Jumble • Java • JUnit • Run from the command-line • Operates on byte code • Runs unit tests on a class • Reporting and documentation could be better • Claims to be faster than Jester • http://jumble.sourceforge.net/index.html
  • 51. 51 © Computas AS 11.03.14 Jumble Sample Report Mutating Foo Tests: FooTest Mutation points = 12, unit test time limit 2.02s .. M FAIL: Foo:31: negated conditional M FAIL: Foo:33: negated conditional M FAIL: Foo:34: - -> + M FAIL: Foo:35: negated conditional ...... Score: 67%
  • 52. 52 © Computas AS 11.03.14 Mutant • Ruby 1.9 and 2.0 • rspec2 • Usually run from the command-line • Good to-the-point reporting • Good performance • OK documentation • Active project • https://github.com/mbj/mutant
  • 53. 53 © Computas AS 11.03.14 Heckle • Ruby 1.8 • Doesn't work on Ruby 1.9 • Test::Unit and rSpec • Usually run from the command-line • Runs a set of unit tests on a class or a method • Good to-the-point reporting • Good performance • Virtually no documentation • http://rubyforge.org/projects/seattlerb/ • http://docs.seattlerb.org/heckle/
  • 54. 54 © Computas AS 11.03.14 Heckle Mutations • Booleans • Numbers • Strings • Symbols • Ranges • Regexes • Branches (if, while, unless, until)
  • 55. 55 © Computas AS 11.03.14 NinjaTurtles • .Net: • C# • Visual Basic/VB.NET • Any other .NET language code • Doesn't seem much alive • http://www.mutation-testing.net/
  • 56. 56 © Computas AS 11.03.14 NinjaTurtles Mutations • Sequence point deletion • Arithmetic operator substitution (*, /, +, -, %) • Bitwise operator substitution (&, |, ^) • Branch substituion (condition, always and never branch) • Conditional boundary substition (< and <=, > and >=) • Substitution of reads from variables, parameters and fields of the same type • Substitution of writes to variables of the same type
  • 57. 57 © Computas AS 11.03.14 Personal Experiences and Recommendations
  • 58. 58 © Computas AS 11.03.14 Experiences and Recommendations • Use mutation testing from day 1 • Start on a small code base • Keep number of unit tests per class low • Have small classes • Select a good tool • Configurable • Flexible • One that can output the mutant
  • 59. 59 © Computas AS 11.03.14 Experiences and Recommendations (cont'd) • Believe the tool • Or try to proof that the tool is wrong • Fix the problem • Don't turn mutation testing off • Embrace the “more than 100%” test coverage • Path coverage • Less code • More unit tests • More intelligent unit tests
  • 60. 60 © Computas AS 11.03.14 Improvements
  • 61. 61 © Computas AS 11.03.14 Improvements • Integration with more unit testing frameworks • Better unit test–source code mapping • Better heuristics • Parallellisation • Better reporting • IDE integration • Building tool integration
  • 62. 62 © Computas AS 11.03.14 Questions? Computas AS Lysaker Torg 45, pb 482 N-1327 Lysaker NORWAY Tel +47-67 83 10 00 Fax +47-67 83 10 01 Org.nr: NO 986 352 325 MVA www.computas.com Contact: [email protected] @filipvanlaenen