SlideShare a Scribd company logo
MUTATION AND CONTRACT
TESTING
CodeteCON #KRK4
Kraków 2018
Mateusz Bryła
AGENDA
Mutation tests
● Concept
● Principle
● Setup
● Summary
Contract tests
● Concept
● Principle
● Setup
● Summary
Can’t make it?
https://medium.com/@mateusz.bryla
https://codete.com/blog/mutation-and-contract-testing/
https://github.com/mbryla
Why?
Mutation and Contract Testing
MUTATION TESTING
first proposed in 1971 (Richard Lipton)
A. Jefferson Offutt and R. H. Untch “Mutation 2000: Uniting the Orthogonal”
first implemented in 1980 (Timothy Budd)
T. A. Budd, “Mutation Analysis of Program Test Data”
Mutation and Contract Testing
Mutation and Contract Testing
Mutation and Contract Testing
MUTATION TESTING
concept
PROBLEM
SOLUTION
EXPECTATIONS
TESTS - TDD?
TESTS - NO TDD?
TEST
MUTATION
TESTING MUTATED CODE...
Mutation and Contract Testing
Mutation and Contract Testing
EXPECTED RESULT
SOMETHING WRONG?
Mutation and Contract Testing
SO. WHAT EXACTLY HAPPENED...
MUTATION TESTING
principle
1. Run your test suites
2. Mutate a piece of production code
3. Run your tests again
4. Find tests that did not fail
5. Repeat steps 2 - 4 with different mutations
MUTATION OPERATORS
BOUNDARY
if (x < y) {
// action
}
is mutated to if (x <= y) {
// action
}
NEGATION
if (x.equals(y)) {
// action
}
is mutated to if (!x.equals(y)) {
// action
}
CONDITIONALS
if (x == y) {
// action
}
is mutated to if (false) {
// action
}
MATH
long x = y + z;
is mutated to
long x = y - z;
RETURN
public MyObj get() {
return new MyObj();
}
is mutated to
public MyObj get() {
new MyObj();
return null;
}
VOID
public long get() {
MyObj myObj = new MyObj();
modify(myObj);
return myObj;
}
is mutated to
public long get() {
MyObj myObj = new MyObj();
return myObj;
}
SURVIVORS
SETUP
Pitest (Java)
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>LATEST</version>
</plugin>
mvn org.pitest:pitest-maven:mutationCoverage
Stryker (JavaScript, Scala, others)
MUTATION TESTING
summary
EXECUTION
100 classes
10 tests / class
1 ms / test
10 mutations / class (100 classes)
EXECUTION
100 classes
10 tests / class
1 ms / test
10 mutations / class (100 classes)
~ 17 minutes
EXECUTION
1000 classes
10 tests / class
1 ms / test
10 mutations / class (1000 classes)
~ 28 hours
SMART EXECUTION
1000 classes
10 tests / class
1 ms / test
10 mutations / class (1000 classes)
~ 2 minutes
real life example: 481 test cases fully mutated on 16GB i7 -> 03:24 min
SURVIVOR STORY
CONTRACT TESTING
first article in 2006 (Ian Robinson)
I. Robinson “Consumer-Driven Contracts: A Service Evolution Pattern”
CONTRACT TESTING
concept
Why?
ARCHITECTURE
service 1 service 3 service 5
service 4
service 2
service 1
(test double)
service 3
(under test)
service 5
(test double)
service 4
(test double)
service 2
(test double)
INTEGRATION TEST
service
(under test)
service
(test double)
SINGLE INTEGRATION
Mutation and Contract Testing
service
(under test)
SINGLE INTEGRATION
service
(sandbox)
INTERFACE
request
response
consumer producer
CONTRACT
consumer producer
when request:
HTTP GET /echo/hello
then response:
HTTP 200
{
“echo”: “hello”
}
CONTRACT TESTING
principle
CONTRACT TEST
service
(under test)
service
when request:
HTTP GET /echo/hello
then response:
HTTP 200
{
“echo”: “hello”
}
tested against
CONTRACT TEST
tested against
when request:
HTTP GET /echo/hello
then response:
HTTP 200
{
“echo”: “hello”
}
service
(under test)
service
PROVIDED
service
(under test)
service
(sandbox)
when request:
HTTP GET /echo/hello
then response:
HTTP 200
{
“echo”: “hello”
}
tested against
CUSTOM
service
(under test)
service
(sandbox)
when request:
HTTP GET /echo/hello
then response:
HTTP 200
{
“echo”: “hello”
}
tested against
SETUP
Spring Cloud Contract (Java)
https://github.com/mbryla/contract-testing
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>2.0.0.M7</version>
<extensions>true</extensions>
<configuration>
<!-- Provide the base class for your auto-generated tests →
<baseClassForTests>com.mbryla.contract.producer.BaseTest</baseClassForTests>
</configuration>
</plugin>
Pact (Ruby, JavaScript, Go, others)
SETUP
package contracts
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url '/echo/hello'
headers {
header('Content-Type', 'application/json;charset=UTF-8')
}
}
response {
status 200
body("{"echo": "hello"}")
headers {
header('Content-Type': 'application/json;charset=UTF-8')
}
}
}
CONTRACT TESTING
summary
FINAL REMARKS
ALL IN ONE - take photos ;)
This presentation - “Mutation and Contract testing” at CodeteCON #4, Kraków 2018
https://medium.com/@mateusz.bryla
https://codete.com/blog/mutation-and-contract-testing/
https://github.com/mbryla
Mutation tests - help verify the quality of your tests
Pitest (Java), Stryker (JavaScript, Scala, others)
mvn org.pitest:pitest-maven:mutationCoverage
Contract tests - protect you from unstable mocks / sandboxes
Spring Cloud Contract (Java), Pact (Ruby, JavaScript, Go, others)
https://github.com/mbryla/contract-testing
Hands Up - Avel Chuklanov - https://unsplash.com/photos/9cx4-QowgLc (CC0 1.0)
Bridge - Franc - https://thenounproject.com/search/?q=bridge&i=122542 (CC BY 3.0 US)
Cargo Truck - No way - https://thenounproject.com/search/?q=truck&i=154864 (CC0 1.0)
Berlin Wall - Unknown - https://commons.wikimedia.org/wiki/File:West_and_East_Germans_at_the_Brandenburg_Gate_in_1989.jpg (CC 1.0)
Linus Torvalds - Unknown - https://commons.wikimedia.org/wiki/Linux#/media/File:Linus_Torvalds.jpeg (CC 3.0)
Poly Bridge - Imgur (respective owners)
https://imgur.com/r/PolyBridge/hgyZIeO
https://imgur.com/r/PolyBridge/yVHKUpz
https://imgur.com/WYpPKbs
https://imgur.com/r/PolyBridge/2hTYZno
Blown bridge - Giphy - https://giphy.com/gifs/explosion-bridge-miFVHkNdJoowM - respective owner
Hilarious little girl - Giphy - https://giphy.com/gifs/AuIvUrZpzBl04 - respective owner
Laser - Yohan Berger - https://thenounproject.com/search/?q=laser&i=36677 (CC BY 3.0 US)
Resurrection - Isabel Martinez Isabel - https://thenounproject.com/search/?q=survived&i=202842 (CC BY 3.0 US)
Pac Man - iconoci - https://thenounproject.com/search/?q=pac+man&i=9215 (CC BY 3.0 US)
Stopwatch - Nick Holroyd - https://thenounproject.com/search/?q=stopwatch&i=12666 (CC BY 3.0 US)
Toolbox - Georgiana Ionescu - https://thenounproject.com/search/?q=toolbox&i=1348711 (CC BY 3.0 US)
Survivors - Gerald Wildmoser - https://thenounproject.com/search/?q=drown&i=208787 (CC BY 3.0 US)
Sandbox - Giphy - https://media.giphy.com/media/AAHUIzS2Oo8UM/giphy.gif - respective owner
Thank you - Gan Khoon Lay - https://thenounproject.com/search/?q=thank%20you&i=854669 (CC BY 3.0 US)
ATTRIBUTIONS
Q / A
Mateusz Bryła
mateusz.bryla@lingmates.com

More Related Content

PPTX
Kotlin Presentation
PDF
次期Internet explorer10とwindows azureで始めるhtml5 api開発
PDF
[Kotlin勉強会] Hello Kotlinの次におさえたいKotlinの勘所
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Design and development of automated tests for the IoT
DOCX
resumelrs_jan_2017
PDF
Engineering Software and Software Lifecycle
PDF
Clean Architecture
Kotlin Presentation
次期Internet explorer10とwindows azureで始めるhtml5 api開発
[Kotlin勉強会] Hello Kotlinの次におさえたいKotlinの勘所
Test-Driven Design Insights@DevoxxBE 2023.pptx
Design and development of automated tests for the IoT
resumelrs_jan_2017
Engineering Software and Software Lifecycle
Clean Architecture

Similar to Mutation and Contract Testing (20)

PDF
AOTB2014: Agile Testing on the Java Platform
PPTX
OpenDaylight Developer Experience 2.0
PPTX
Tdd & clean code
PPT
Amost 2011 keynote
PDF
Microservices Chaos Testing at Jet
PDF
Test Smart, not hard
PDF
M2M for Java Developers: MQTT with Eclipse Paho - Eclipsecon Europe 2013
PDF
Keynote VST2020 (Workshop on Validation, Analysis and Evolution of Software ...
PDF
Functional and non-functional testing with IoT-Testware
PDF
Architecture Patterns with Python 1st Edition Harry Percival
PDF
TDD-and-Hexagonal-Architecture-in-Microservices-CraftHub.pdf
PDF
Instant download Architecture Patterns with Python 1st Edition Harry Percival...
PDF
Testing distributed systems in production
PDF
The Ring programming language version 1.8 book - Part 92 of 202
PDF
Hardening
PDF
MUTANTS KILLER - PIT: state of the art of mutation testing system
ODP
Microservices Manchester: Testing Microservices: Pain or Opportunity? By Davi...
PDF
Leveraging CI/CD to improve open stack operation
PDF
Advanced Testing with TTCN-3 and UML Testing Profile
PPTX
Testing micro services using testkits
AOTB2014: Agile Testing on the Java Platform
OpenDaylight Developer Experience 2.0
Tdd & clean code
Amost 2011 keynote
Microservices Chaos Testing at Jet
Test Smart, not hard
M2M for Java Developers: MQTT with Eclipse Paho - Eclipsecon Europe 2013
Keynote VST2020 (Workshop on Validation, Analysis and Evolution of Software ...
Functional and non-functional testing with IoT-Testware
Architecture Patterns with Python 1st Edition Harry Percival
TDD-and-Hexagonal-Architecture-in-Microservices-CraftHub.pdf
Instant download Architecture Patterns with Python 1st Edition Harry Percival...
Testing distributed systems in production
The Ring programming language version 1.8 book - Part 92 of 202
Hardening
MUTANTS KILLER - PIT: state of the art of mutation testing system
Microservices Manchester: Testing Microservices: Pain or Opportunity? By Davi...
Leveraging CI/CD to improve open stack operation
Advanced Testing with TTCN-3 and UML Testing Profile
Testing micro services using testkits
Ad

Recently uploaded (20)

PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
assetexplorer- product-overview - presentation
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Introduction to Artificial Intelligence
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
assetexplorer- product-overview - presentation
VVF-Customer-Presentation2025-Ver1.9.pptx
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction to Artificial Intelligence
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Computer Software and OS of computer science of grade 11.pptx
Wondershare Filmora 15 Crack With Activation Key [2025
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
Softaken Excel to vCard Converter Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Ad

Mutation and Contract Testing