Microservices Testing
Strategy
The Journey has begun
What are
Microservices?
Micro-services is an architecture
consisting of focused, small
services that together create a
complete application or task.
Every instance of a micro-
service represents a single
responsibility within the
solution.
Key feature of microservices
architecture
•Self-contained and componentized
•Decentralized data management
•Resilient to failures
•Built around a single business need
•Reasonably small micro
Important Testing Scenarios
Good use case of Microservices Architecture is following scenarios where:
1. The system is too complex or too big and it becomes difficult to manage
2. The system is expected to handle high traffic & load and needs to be highly scalable
3. Testing between internal microservices and a third-party services
4. Testing for microservices that is to be exposed to public domain
Challenges in testing microservices
• Timely availability of all the services for testing
• Complicated extraction of logs during testing and data validation
• Identifying scope of testing at each service level and integration testing as each component work on
separate services and rely on each other to cover their module and integration with external service
• Considering the development strategy is agile, then availability of testing environment is another major
challenge
• Due to distributed and independent nature of a microservice architecture, each component of
architecture is isolated from the rest, they need to test individually and cover all the independent
services
• Monitoring multiple log files, databases, and servers, which increases the complexity of tracking down
issues or verifying processes
Microservices testing strategy
• Bottom-up testing – Bottom up testing approach will be followed to get the
optimized solution
• Test the domain
• Tests closer to the code
• Integrate Early
• Use Mocks / Stubs
• Focus is on Test Pyramid
• Helps visualize/categorize test coverage better
Microservices
testing types
Unit testing
• Focus on one unit (class/module) of
domain
• Verify functionality of one unit
• White box & API testing
Unit testing helps us in the following
ways:
• Isolate the logic in places where setting
up all the cases and covering edge
scenarios is much easier than at a
service level
• Internal dependencies are stubbed and
mocked
• The non-functional requirements such
as end-user authentication, throttling,
monitoring, etc. implemented at each
and every microservice level.
C2
B2A1
A2
Y1
Z2
Z1
D1
P2
D2
1P
B1
C1
X1
INDIVIDUAL MODULE/CLASS
TESTING
Contract testing
• Individual microservice signatures (end
points) are the focus point along with
other services that will consume the
service under test.
• Test doubles (mocks) are used to
simulate the behavior of consumer
microservices.
• One end-point at a time is tested
• Each service is treated as a black box
• Tests are end-to-end within the bounds
of the service
• Assertion are on response e.g. JSON
body.
Contract testing helps:
• Stub out the dependencies.
• Ensure catching defect within workflows
• To identify defect for each service in isolation
• Complexity to test individual services is less
• Services and providers are more stable
• Test data set-up is easy
• Get instant feedback on individual service
• Identify unused interface at initial level
Integration testing
• An integration test verifies the communication
paths and interactions between components to
detect interface defects. This critical part of testing
a microservices for proper inter-service
communication
• Integration testing with data stores and external
components
Integration Testing Helps
• Interservice communication issues
• Provide additional coverage from unit and contract testing
for each integration point
• Identify defect for below cases of integration point
• Gateway Integration
• Integration with data stores
• Interservice/ external component integration
Resource
Domain
External
Client
ORM
Data Store
Test Client
Stubbed
Service
End to end testing
• End-to-end testing verifies that the entire
process flows work correctly, including all
services and DB integration
• End to end testing is more business facing as
system is deployed and treated as black box
• It also, verifies environment setup, configuration,
firewall, proxies, load balancer are correctly
configured
End to end testing helps:
• Ensure complete correctness & health of
application
• Reduce future risk due to coverage gap
• Analyze user experience while using end
to end workflow and various aspect of
application
UI testing
User interface testing is most important as it tests the
system as an end-user and end user input is random and
very erratic
All the databases, interfaces, internal and third-party
services must work together seamlessly to get the
expected results
This is verifies and validated the user interface
User Interface testing helps:
• It provide perspective of end user and therefore it can
identify the hidden issue which not identified earlier
in functional testing
• Compatibility with different browser and devices
Tool to Test
microservices
Tool Type of Testing Type of License
SOAP UI
API
Free open source version and Pro Version
Rest- Assured Open source
Postman Open source
SOAtest Open source
PRACT
Contract Testing Open source
PACTO
Janus
AppDynamics
Monitoring
Free 14-day Trial, then from $230 monthly.
TraceView $39.50/host/month
NewRelic Free plan, then from $149 per month.
Jmeter
Performance
testing
Open source
NeoLoad Licensed
Loadrunner Licensed
Conclusion
• Established best practices like the Test Pyramid
• Common tests across all Microservices can turn into a
bottleneck and therefore should be reduced, for
example by performing more consumer-driven contract
tests.
• With suitable tools Stubs, can be created from
Microservices.

Microservices testing strategy-v2

  • 1.
  • 2.
    What are Microservices? Micro-services isan architecture consisting of focused, small services that together create a complete application or task. Every instance of a micro- service represents a single responsibility within the solution. Key feature of microservices architecture •Self-contained and componentized •Decentralized data management •Resilient to failures •Built around a single business need •Reasonably small micro
  • 3.
    Important Testing Scenarios Gooduse case of Microservices Architecture is following scenarios where: 1. The system is too complex or too big and it becomes difficult to manage 2. The system is expected to handle high traffic & load and needs to be highly scalable 3. Testing between internal microservices and a third-party services 4. Testing for microservices that is to be exposed to public domain
  • 4.
    Challenges in testingmicroservices • Timely availability of all the services for testing • Complicated extraction of logs during testing and data validation • Identifying scope of testing at each service level and integration testing as each component work on separate services and rely on each other to cover their module and integration with external service • Considering the development strategy is agile, then availability of testing environment is another major challenge • Due to distributed and independent nature of a microservice architecture, each component of architecture is isolated from the rest, they need to test individually and cover all the independent services • Monitoring multiple log files, databases, and servers, which increases the complexity of tracking down issues or verifying processes
  • 5.
    Microservices testing strategy •Bottom-up testing – Bottom up testing approach will be followed to get the optimized solution • Test the domain • Tests closer to the code • Integrate Early • Use Mocks / Stubs • Focus is on Test Pyramid • Helps visualize/categorize test coverage better
  • 6.
  • 7.
    Unit testing • Focuson one unit (class/module) of domain • Verify functionality of one unit • White box & API testing Unit testing helps us in the following ways: • Isolate the logic in places where setting up all the cases and covering edge scenarios is much easier than at a service level • Internal dependencies are stubbed and mocked • The non-functional requirements such as end-user authentication, throttling, monitoring, etc. implemented at each and every microservice level. C2 B2A1 A2 Y1 Z2 Z1 D1 P2 D2 1P B1 C1 X1 INDIVIDUAL MODULE/CLASS TESTING
  • 8.
    Contract testing • Individualmicroservice signatures (end points) are the focus point along with other services that will consume the service under test. • Test doubles (mocks) are used to simulate the behavior of consumer microservices. • One end-point at a time is tested • Each service is treated as a black box • Tests are end-to-end within the bounds of the service • Assertion are on response e.g. JSON body. Contract testing helps: • Stub out the dependencies. • Ensure catching defect within workflows • To identify defect for each service in isolation • Complexity to test individual services is less • Services and providers are more stable • Test data set-up is easy • Get instant feedback on individual service • Identify unused interface at initial level
  • 9.
    Integration testing • Anintegration test verifies the communication paths and interactions between components to detect interface defects. This critical part of testing a microservices for proper inter-service communication • Integration testing with data stores and external components Integration Testing Helps • Interservice communication issues • Provide additional coverage from unit and contract testing for each integration point • Identify defect for below cases of integration point • Gateway Integration • Integration with data stores • Interservice/ external component integration Resource Domain External Client ORM Data Store Test Client Stubbed Service
  • 10.
    End to endtesting • End-to-end testing verifies that the entire process flows work correctly, including all services and DB integration • End to end testing is more business facing as system is deployed and treated as black box • It also, verifies environment setup, configuration, firewall, proxies, load balancer are correctly configured End to end testing helps: • Ensure complete correctness & health of application • Reduce future risk due to coverage gap • Analyze user experience while using end to end workflow and various aspect of application
  • 11.
    UI testing User interfacetesting is most important as it tests the system as an end-user and end user input is random and very erratic All the databases, interfaces, internal and third-party services must work together seamlessly to get the expected results This is verifies and validated the user interface User Interface testing helps: • It provide perspective of end user and therefore it can identify the hidden issue which not identified earlier in functional testing • Compatibility with different browser and devices
  • 12.
    Tool to Test microservices ToolType of Testing Type of License SOAP UI API Free open source version and Pro Version Rest- Assured Open source Postman Open source SOAtest Open source PRACT Contract Testing Open source PACTO Janus AppDynamics Monitoring Free 14-day Trial, then from $230 monthly. TraceView $39.50/host/month NewRelic Free plan, then from $149 per month. Jmeter Performance testing Open source NeoLoad Licensed Loadrunner Licensed
  • 13.
    Conclusion • Established bestpractices like the Test Pyramid • Common tests across all Microservices can turn into a bottleneck and therefore should be reduced, for example by performing more consumer-driven contract tests. • With suitable tools Stubs, can be created from Microservices.