TESTING
MICROSERVICES
ARCHITECTURES
Renan Martins @renan89
1
DEFINITION
2
“Micro services are small, autonomous
services that work together"
SMALL
3
Focused on Doing One Thing Well
AUTONOMOUS
4
Need to be able to change independently of each other,
and be deployed by themselves without requiring
consumers to change.
AM I DOING IT RIGHT?
5
Can you make a change to a service and
deploy it by itself without changing
anything else?
6
KEY BENEFITS OF
MICRO SERVICES
ARCHITECTURES
TECHNOLOGY HETEROGENEITY
7
The right tool for each job!
POSTS
<<ruby>>
FRIENDS
<<golang>>
PICTURES
<<java>>
<<Document Store>> <<graph DB>> <<Blob Store>>
RESILIENCE
8
We can build systems that handle the total failure of
services and degrade functionality accordingly
SCALING
PICTURES
POSTS
FRIENDS
EASE OF DEPLOYMENT
Deploys are faster, independent and
problems can be isolated more easily
ORGANIZATIONAL ALIGNMENT
INVOICING SERVICE
INVENTORY SERVICE
Smaller teams and smaller codebases
Conway's Law
COMPOSABILITY AND REPLACEABILITY
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
HTTPS
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
New Point of Sale
HTTPS
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
New Point of Sale
HTTPS
HTTP
COMPOSABILITY AND REPLACEABILITY
MONOLITHIC ECOM SYSTEM
PROFILE
MODULE
New Point of Sale
HTTPS
HTTP
Affiliate Store
HTTPS
13
NO
YOU MUST BE THIS TALL TO USE MICRO SERVICES
http://martinfowler.com/bliki/MicroservicePrerequisites.html
MONOLITH FIRST
15
http://martinfowler.com/bliki/MonolithFirst.html
16
TESTS
17
TEST AUTOMATION
CLOSER TO
THE USER
CLOSER TO
THE DEVELOPER
$$$
SLOWER / FEWER
$
FASTER / MORE
USER
JOURNEY
UI
INTEGRATION
UNIT
Connection of UI tests to a persona like flow through the system
Testing on the level of the users - incl. browser, network, databases, external systems, …
Tests of multiple integrated method
Tests of single methods without dependencies
18
CODE PRODUCTION
Unit, Integration, end
to end tests, smoke
tests, etc..
Consumers
19
HOW DOES IT
RELATE TO MICRO
SERVICES
ARCHITECTURES ?
ANATOMY OF A MICROSERVICE
20http://martinfowler.com/articles/microservice-testing/
UNIT TESTING MICROSERVICES
21
Domain - We should focus on
testing the behavior, observing
changes on its state.
Gateways, Resources and
Persistence - We should focus
on the interactions and
collaboration (Mocks, test
doubles)
http://martinfowler.com/articles/microservice-testing/
INTEGRATION TESTS - PERSISTENCE E GATEWAYS
22http://martinfowler.com/articles/microservice-testing/
COMPONENT TESTS - IN PROCESS
23http://martinfowler.com/articles/microservice-testing/
COMPONENT TESTS - OUT OF PROCESS
24http://martinfowler.com/articles/microservice-testing/
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
25
Mock your APIs for fast,
robust and comprehensive
testing
mountebank - over the wire
test doubles
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
Configure the stubs
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
Configure the stubs
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
SMTP TCP
Stub
HTTP
Configure the stubs
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
Your application
SMTP TCP
Stub
HTTP
Configure the stubs
COMPONENT TESTS - HOW TO SIMULATE EXTERNAL SERVICES?
26
test
Your application
SMTP TCP
Stub
HTTP
Configure the stubs
COMPONENT TESTS - PROBLEMS WITH STUBS
27
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Your application Stub / Imposter
Test
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
Your application Stub / Imposter
Test
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
Your application Stub / Imposter
Test
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
COMPONENT TESTS - PROBLEMS WITH STUBS
27
Service
constantly
evolving
How frequently do you change your stubs?
BECOMES
INVALID!
Your application Stub / Imposter
Test
Becomes
invalid!
CONTRACT TESTS
28
Service
constantly
evolving
CONSUMER DRIVEN CONTRACTS
29
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS
29
Service
constantly
evolving
UNIT
INTEGRATION
COMPONENT
CONTRACT
Deploy!
Service's Continuous Integration Pipeline
CONSUMER DRIVEN CONTRACTS - IMPLEMENTATIONS
30
https://github.com/realestate-com-au/pact
END TO END TESTS - BLACK BOX
31
END TO END TESTS - BLACK BOX
31
END TO END TESTS - BLACK BOX
31
1
4
2
3
5
6
7
8
END TO END TESTS - BLACK BOX
31
1
4
2
3
5
6
7
8
END TO END TESTS - BLACK BOX
31
1
4
2
3
5
6
7
8
END TO END TESTS - BLACK BOX
31
1
4
2
3
5
6
7
8
GOOD LUCK!
END TO END TESTING MICRO SERVICES ARCHITECTURES
32
Avoid the need for end-to-end tests
wherever possible
END TO END TESTING MICRO SERVICES ARCHITECTURES
33
Test User Journeys, not stories
END TO END TESTING MICRO SERVICES ARCHITECTURES
34
Make sure your end to end tests are
independent of existing data
CI PIPELINE - QUICK FEEDBACK VS COST
35
UNIT
INTEGRATION
CONTRACT
COMPONENT
JOURNEYS
WE COVERED THE WHOLE PYRAMID. ARE WE DONE YET?
36
WE COVERED THE WHOLE PYRAMID. ARE WE DONE YET?
36
Nope.
WE COVERED THE WHOLE PYRAMID. ARE WE DONE YET?
36
Nope.
Testing in production!
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
SERVICE
V2
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
SERVICE
V2
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
SERVICE
V2
TESTING IN PRODUCTION
37
Deploy vs Release
BLUE GREEN
DEPLOYMENT
SERVICE
V1
SERVICE
V2
CANARY RELEASE
38
CANARY RELEASE
38
CANARY RELEASE
38
CANARY RELEASE
38
SERVICE
V1
CANARY RELEASE
38
SERVICE
V1
CANARY RELEASE
38
SERVICE
V1
SERVICE
V2
CANARY RELEASE
38
SERVICE
V1
SERVICE
V2
CANARY RELEASE
38
SERVICE
V1
SERVICE
V2
CANARY RELEASE
38
SERVICE
V1
SERVICE
V2
CANARY RELEASE
38
SERVICE
V1
SERVICE
V2
15%
85%
MEAN TIME TO RECOVER
39
Tests are very important to reduce the amount of
defects in our systems. However, it's important to
acknowledge that bugs will always happen in
production. 

How fast we can recover from them will help
determining our success!
TECH RADAR RECOMMENDS!
40
http://www.thoughtworks.com/radar
rmartins@thoughtworks.com
¡MUCHAS GRACIAS!

Testing Microservices Architectures