SlideShare a Scribd company logo
The Cake Your Test
Coverage is a Lie!
Chris Shepherd
© 2020 ThoughtWorks
Hi!
Photo by luis gomes from Pexels
Testing!
Your test coverage is a lie!
Your test coverage is a lie!
Photo by Min An from Pexels
● Common testing strategies
● Exciting errors (and where to find them)
● Mutation testing and its history
● Stryker Mutator - A fun framework for finding
mutants
● Some other bits and bobs
So what's the plan, Stan?
© 2020 ThoughtWorks
© 2020 ThoughtWorks© NASA
© NASA
© NASA
© NASA
© NASA
© Photo by Rebekah Howell on Unsplash
© NASA
Your test coverage is a lie!
Your test coverage is a lie!
Manual,
Exploratory
Tests
Unit Tests
Service Tests
UI /
E2E Tests
Unit Tests
Service Tests
UI /
E2E Tests
Manual,
Exploratory
Tests
Unit Tests
Service Tests
UI /
E2E Tests
Manual,
Exploratory
Tests
Unit Tests
Service Tests
UI /
E2E Tests
Manual,
Exploratory
Tests
Manual,
Exploratory
Tests
Photo by Jake Davies on Unsplash
Photo by Giorgio Trovato on Unsplash
Static Type System
Unit Tests
Integration Tests
E2E Tests
Photo by Sanjay Shivakumar on Unsplash
Integrated Tests
Integration Tests
Implementation
Details
Your test coverage is a lie!
Photo by Somben Chea from Pexels
Manual,
Exploratory
Tests
Unit Tests :(
Photo by Sarah Kilian on Unsplash
The
Competent
Programmer
Hypothesis.
Your test coverage is a lie!
Mutation
Testing.
Problem One
The Oracle Problem
“In order to use testing to validate a
program it is necessary to assume the
existence of a test oracle which can be used
to check the correctness of test output.”
- William Howden, 1978
Problem Two
Photo by Gustavo Fring from Pexels
The Reliable Test Set Problem
● Surfaced in 1971
● An answer to validating a Reliable Test Set
● Seed defects in your software to create Mutants
● Re-evaluate your tests to verify their efficacy
● Profit
In a Nutshell
Photo by Dollar Gill on Unsplash
Photo by Jean-Baptiste Burbaud from Pexels
The
Coupling
Effect
Hypothesis.
Your test coverage is a lie!
Your test coverage is a lie!
execute(operation, args) {
if (operation //= "ADD") {
this.toDoList.push(args);
}
return this.toDoList;
}
it("Adds Items", () /> {
const toDoList = new ToDoList();
const list = toDoList.execute("ADD", "Write the Tests");
expect(list).toEqual(["Write the Tests"]);
});
File % Stmts % Funcs % Lines
All files 100 100 100
utils.js 100 100 100
execute(operation, args) {
if (operation //= "ADD") {
this.toDoList.push(args);
}
return this.toDoList;
}
it("Adds Items", () /> {
const toDoList = new ToDoList();
const list = toDoList.execute("ADD", "Write the Tests");
expect(list).toEqual(["Write the Tests"]);
});
execute(operation, args) {
if (true) {
this.toDoList.push(args);
}
return this.toDoList;
}
<- Before
After ->
File % Stmts % Funcs % Lines
All files 100 100 100
utils.js 100 100 100
Your test coverage is a lie!
//.
if (this.toDoList[i] != item) {
return this.toDoList;
}
//.
Decision Mutations
//.
if (true) {
return this.toDoList;
}
//.
//.
execute(operation, args) {
if (operation //= "ADD") {
this.toDoList.push(args);
}
return this.toDoList;
}
//.
Statement Mutations
//.
execute(operation, args) {
if (operation //= "ADD") {
this.toDoList.push(args);
this.toDoList.push(args);
}
return this.toDoList;
}
//.
…
for (i = 0; i < toDoList.length; i/+) {
if (this.toDoList[i] //= item) {
return this.toDoList;
}
this.toDoList.push(item);
}
//.
Value Mutations
…
for (i = 0; i /= toDoList.length; i/+) {
if (this.toDoList[i] //= item) {
return this.toDoList;
}
this.toDoList.push(item);
}
//.
Photo by Andrea Piacquadio from Pexels
Photo by Simon Berger on Unsplash
Photo by Federica Galli on Unsplash
Photo by Marvin Meyer on Unsplash
Your test coverage is a lie!
Photo by David Levêque on Unsplash
Welcome
To
The
Robo-Bar!
http://qrco.de/bbZArc
$ git clone https://github.com/stryker-mutator/robobar-example
$ cd robobar-example
$ npm install
$ npm test
$ npm run stryker
Stryker: Getting Started
Coverage Report
Photo by Jamie Street on Unsplash
Mutation Report
Your test coverage is a lie!
Photo by Element5 Digital from Pexels
Residual Defect
Density
(RDD)
Photo by William Iven on Unsplash
Defect Count
Total # Lines of Code
13
2000
0.065/LoC
6.5/KLoC
Using Mutation Testing
to Estimate RDD
Learned RDD
X
Mutation Score
Code Coverage is a Lie
Mutation Scores Highlight Blindspots
Residual Defect Density is a Thing
Mutation Scores Can Predict RDD
Photo by Ian Espinosa on Unsplash
Photo by Ian Espinosa on Unsplash
Photo by bruno neurath-wilson on Unsplash
Photo by Lama Roscu on Unsplash
Your test coverage is a lie!
Photo by taylor hernandez on UnsplashPhoto by taylor hernandez on Unsplash
Your test coverage is a lie!
Photo by Brian McGowan on Unsplash
Chris Shepherd
Ta
© 2020 ThoughtWorks
References
● Metamorphic Testing: A Review of Challenges and Opportunities - Tsong Yueh Chen et al
● Investigations of the Software Testing Coupling Effect - A. Jefferson Offutt
● Mutant census: An empirical examination of the competent programmer hypothesis - Gopinath, Rahul et al
● Mutation Testing - Stuart Anderson
● Fault-Based Testing - Mauro Pezzè & Michal Young
● Fault-Based Testing Without the Need of Oracles - TY Chen
● Theoretical and Empirical Studies of Program Testing - William Howden
● https://stryker-mutator.io/ - This is really good, you should check it out!
@the_sheps
me@thesheps.dev
thesheps.dev
© 2020 ThoughtWorks
Continue the
conversation on Slack
© 2020 ThoughtWorks
XConfEurope2020
xconfeurope2020.slack.com
#talk6-your-test-coverage-is-a-lie
#XConfOnline

More Related Content

Your test coverage is a lie!