If you can't read please download the document
Upload
thoughtworks
View
9.577
Download
0
Embed Size (px)
Citation preview
Slide 1
Testing Strategies for Micro-services Architecture
Ketan SoniJesal Mistry
June 2014
Brief IntroThere has been a shift in service based architectures over the last few years towards smaller, more focussed "micro" services. There are many benefitswith this approach such as the ability to independently deploy, scale and maintain each component.
Our team has spent the last two years building and deploying more than 10microservices into production, and we plan to create a few more.Here we would like to discuss a number of approaches and testing strategies for managing the testing of independently deployable components.
What is a micro-service?
Ask the audience
Example
I want to purchase a product from an e-commerce website
Monolithic system
MasterCard / VisaLogistics
CartCatalogAuthenticationPaymentFulfilment
E-commerce website
Unixphilosophy:
Write programs that doone thing and do itwell.
A system built using micro-services is a system that is built up of small, lightweight services, where each performs a single function. The services are arranged in independently deployable groups and communicate with each other via a well defined interface and work together to provide business value.
Micro-Services system
MasterCard / VisaLogistics
Cart Service
Payment ServiceAuthentication ServiceFulfilment Service
Catalog Service
E-commerce website
Challenges in testing
Distributed system complexity
Inter service communication
Asynchronous nature
Dependency management
Challenges in testing
- as good as having different teams, working on different services
Testing Strategies
Top-down
Big Bang
Hybrid / Context Driven
Bottom-up
- top down- having UI test- brittleness- high maintenance- slow feedback- big bang- testing after the fact (app is ready & done)- hybrid/context- mix of approaches- bottom up
Our Approach
Bottom-up testing Test the domain
Tests closer to the code
Integrate Early
Use Mocks / Stubs
Focus is on Test Pyramid
Helps visualize/categorize test coverage better
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
Bottom-up testing
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
Unit Test Layer
Test the domain
Should focus on the code under test
Maximum test coverage
Unit Test Layer
Authentication ServicePayment ServiceCatalog Service
Unit tests
- addItem- removeItem- verifyCreditCardCart ServiceFulfilment Service
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
Contract Test Layer
Test one end-point at a time
Treat the service as a black box
These tests are end to end within the bounds of the service
Assertion are on response e.g. JSON body
Stub out the dependencies
Contract Test Layer
Contract Test Layer
Contract Test Layer
Contract tests
Add Item to cart
POST /cart/{:product_id}
HTTP Request
HTTP Response
JSON
....
Cart ServiceMockAuthentication Service
MockCatalog ServiceMockFulfilment ServiceMockPayment Service
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
Test Pyramid
The goal of these tests is to execute as much of the application code as possible as quickly as possible. The basic idea is to run up all your services in memory and connect them via in memory http pipes.
End to End Integration Test layer
Test End to End user journey to make sure that the business flow works as expected
These covers interaction of all the available services
End to End Integration Test Layer
End to End Integration Test layer
E2E Integration tests
Cart ServicePlace an order
Payment ServiceAuthentication ServiceCatalog ServiceFulfilment ServiceVerify that the order is placed
MockLogisticsMockMastercard
End to End Integration Test Layer
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
Consumer Driven Contract Test layer
In case of third-party system, we had tests to make sure that external systems behave the way we expect them to.
Consumer Driven Contract Test Layer
Consumer Driven Contract Test layer
Consumer Driven Contract tests
Verify Credit Card
MasterCard / VisaService
Consumer Driven Contract Test Layer
Verify Credit Card
HTTP Request
HTTP Response
Success
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
UI Test Layer
For the UI layer, we wrote tests for the End to End user journey which also covered the external 3rd party interactions
UI tests were minimal
UI Test Layer
User Interface Journey tests
Authentication ServiceFulfilment ServicePayment ServiceCart Service
As a userI should be able to purchase a mobile from a websiteUIMasterCard / VisaLogistics
Test Pyramid
Unit
Contract
E2E Integration
UI
Consumer Driven Contract
Manual / Exploratory
References
Logging
Inter - Service effects
Gracefully handle errors
Look & Feel
Manual / Exploratory
References
http://en.wikipedia.org/wiki/Unix
http://davidmorgantini.blogspot.co.uk/2014/03/microservices-effective-testing.html
http://martinfowler.com/articles/microservices.html
https://github.com/tobyclemson
References
Questions ?