Microservices
Testing Strategy
Rajni Singh,
Manager, Quality Assurance
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 microservice
represents a single responsibility
within the solution.
Key features of
microservices architecture:
• Self-contained and
componentized
• Decentralized data
management
• Resilient to failures
• Built around a single
business need
• Reasonably small
micros
Important testing scenarios
A good use case of a microservices architecture would
include the following scenarios:
1. The system is too big and complex that it becomes
difficult to manage.
2. The system is expected to handle high traffic & load
and needs to be scalable.
3. Testing between internal microservices and a third-
party services.
4. Testing for microservices which needs to be exposed
to the public domain.
Challenges in testing microservices
• Timely availability of all the services for testing.
• Complicated extraction of logs during testing and data validation.
• Identifying the scope of testing at each service level and
integration testing as each component operate on separate
services and rely on each other to cover their module and
integration with an external service.
• The availability of testing environment considering the
development strategy is agile.
• Distributed and independent nature of a microservice
architecture results in the isolation of each component of the
architecture from the rest. Thus it needs individual testing and
cover all independent services.
• Monitoring multiple log files, databases, and servers increases
the complexity of tracking down issues or verifying processes.
Microservices testing strategy
Bottom-up testing approach is an optimized solution
which includes:
• 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
UI testing
Integration testing
End to end testing
Contract testing
Unit testing
Exploratory testing
Scopeoftesting
Executiontime
Number of tests
• Focuses on one unit (class/module) of a domain
• Verifies functionality of one unit
• White box & API testing
Unit testing helps us in the following
ways:
• Isolates 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.
• Non-functional requirements such as
end-user authentication, throttling,
monitoring, etc. are implemented at
each and every microservice level.
Unit testing
A1
G3
X1 Z2
D1
C3
A9 D6
B4 D7
B1 X2
Individual
module/Class
testing
• Individual microservice signatures (end points) are the focus 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 dependencies.
• Ensure defect identification within
workflows.
• Identify defect for each service in isolation.
• Decrease complexity to test individual
services.
• Stabilize services and providers.
• Set-up test data easily.
• Get instant feedback on individual service.
• Identify unused interface at initial level.
Contract testing
Mock Authentication
Service
Mock Catalog
Service
Mock Payment
Service
Mock Fulfilment
Service
Cart Service
POST /cart/{:product_id}
HTTP Request
JSON
HTTP Response
Test Client
• An integration test verifies the communication paths and interactions between components to detect interface defects. This
is a critical part of testing a microservices for proper inter-service communication.
• Integration testing is done with data stores and external components.
Integration Testing Helps
• Inter-service communication issues.
• Provide additional coverage from unit and
contract testing for each integration point.
• Identify defsect for the following cases of
integration point:
o Integration with data stores
o Gateway Integration
o Inter-service/external component
integration
Integration testing
Resource
Domain
External
Client
ORM
Stubbed
Service
Data Store
• End-to-end testing verifies that the entire process flows correctly, including all services and DB integration.
• End-to-end testing is more business facing as system is deployed and treated as a black box.
• It verifies environment setup, configuration, firewall, proxies, load balancer are correctly configured as well.
End-to-end testing helps:
• Ensure complete correctness and
health of the application.
• Reduce future risk due to coverage
gap.
• Analyze user experience while
using end-to-end workflow and
various aspects of the application.
End-to-end testing
Authentication
Service
Catalog Service
Payment Service
Fulfilment Service
Cart Service
Place and order
Verify that the
order is placed
Mock Mastercard
Mock Logistics
• User interface testing is most important as it tests the system as an end-user and the 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 done to verify and validate the user interface.
User Interface testing helps:
• Provide perspective of end user and
therefore can identify the hidden
issue which was not identified earlier
during functional testing.
• Compatibility with multiple browsers
and devices.
UI testing
UI
Cart Service
Authentication
Service
Payment Service
Fulfilment
Service
Mock Mastercard Mock Logistics
Tools 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
• Established best practices like the Test Pyramid
• Common tests across all Microservices can turn into a bottleneck, therefore
should be reduced, for example by performing more consumer-driven
contract tests.
• With suitable tools Stubs can be created from Microservices.
Conclusion
Nagarro drives technology-led business breakthroughs for industry leaders and challengers. When our
clients want to move fast and make things, they turn to us. Some of our clients include Siemens, GE,
Lufthansa, Viacom, Estēe Lauder, ASSA ABLOY, Ericsson, DHL, Mitsubishi, BMW, the City of New York, T-
Systems, SAP and Infor. Working with these clients, we continually push the boundaries of what is possible
to do through technology, and in what time frame.
Today, we are more than 5,000 experts across 20 countries. Together we form Nagarro, the global services
division of Munich-based Allgeier SE.

Testing Microservices

  • 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 microservice represents a single responsibility within the solution. Key features of microservices architecture: • Self-contained and componentized • Decentralized data management • Resilient to failures • Built around a single business need • Reasonably small micros
  • 3.
    Important testing scenarios Agood use case of a microservices architecture would include the following scenarios: 1. The system is too big and complex that it becomes difficult to manage. 2. The system is expected to handle high traffic & load and needs to be scalable. 3. Testing between internal microservices and a third- party services. 4. Testing for microservices which needs to be exposed to the public domain.
  • 4.
    Challenges in testingmicroservices • Timely availability of all the services for testing. • Complicated extraction of logs during testing and data validation. • Identifying the scope of testing at each service level and integration testing as each component operate on separate services and rely on each other to cover their module and integration with an external service. • The availability of testing environment considering the development strategy is agile. • Distributed and independent nature of a microservice architecture results in the isolation of each component of the architecture from the rest. Thus it needs individual testing and cover all independent services. • Monitoring multiple log files, databases, and servers increases the complexity of tracking down issues or verifying processes.
  • 5.
    Microservices testing strategy Bottom-uptesting approach is an optimized solution which includes: • 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.
    Microservices testing types UI testing Integrationtesting End to end testing Contract testing Unit testing Exploratory testing Scopeoftesting Executiontime Number of tests
  • 7.
    • Focuses onone unit (class/module) of a domain • Verifies functionality of one unit • White box & API testing Unit testing helps us in the following ways: • Isolates 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. • Non-functional requirements such as end-user authentication, throttling, monitoring, etc. are implemented at each and every microservice level. Unit testing A1 G3 X1 Z2 D1 C3 A9 D6 B4 D7 B1 X2 Individual module/Class testing
  • 8.
    • Individual microservicesignatures (end points) are the focus 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 dependencies. • Ensure defect identification within workflows. • Identify defect for each service in isolation. • Decrease complexity to test individual services. • Stabilize services and providers. • Set-up test data easily. • Get instant feedback on individual service. • Identify unused interface at initial level. Contract testing Mock Authentication Service Mock Catalog Service Mock Payment Service Mock Fulfilment Service Cart Service POST /cart/{:product_id} HTTP Request JSON HTTP Response
  • 9.
    Test Client • Anintegration test verifies the communication paths and interactions between components to detect interface defects. This is a critical part of testing a microservices for proper inter-service communication. • Integration testing is done with data stores and external components. Integration Testing Helps • Inter-service communication issues. • Provide additional coverage from unit and contract testing for each integration point. • Identify defsect for the following cases of integration point: o Integration with data stores o Gateway Integration o Inter-service/external component integration Integration testing Resource Domain External Client ORM Stubbed Service Data Store
  • 10.
    • End-to-end testingverifies that the entire process flows correctly, including all services and DB integration. • End-to-end testing is more business facing as system is deployed and treated as a black box. • It verifies environment setup, configuration, firewall, proxies, load balancer are correctly configured as well. End-to-end testing helps: • Ensure complete correctness and health of the application. • Reduce future risk due to coverage gap. • Analyze user experience while using end-to-end workflow and various aspects of the application. End-to-end testing Authentication Service Catalog Service Payment Service Fulfilment Service Cart Service Place and order Verify that the order is placed Mock Mastercard Mock Logistics
  • 11.
    • User interfacetesting is most important as it tests the system as an end-user and the 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 done to verify and validate the user interface. User Interface testing helps: • Provide perspective of end user and therefore can identify the hidden issue which was not identified earlier during functional testing. • Compatibility with multiple browsers and devices. UI testing UI Cart Service Authentication Service Payment Service Fulfilment Service Mock Mastercard Mock Logistics
  • 12.
    Tools 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.
    • Established bestpractices like the Test Pyramid • Common tests across all Microservices can turn into a bottleneck, therefore should be reduced, for example by performing more consumer-driven contract tests. • With suitable tools Stubs can be created from Microservices. Conclusion Nagarro drives technology-led business breakthroughs for industry leaders and challengers. When our clients want to move fast and make things, they turn to us. Some of our clients include Siemens, GE, Lufthansa, Viacom, Estēe Lauder, ASSA ABLOY, Ericsson, DHL, Mitsubishi, BMW, the City of New York, T- Systems, SAP and Infor. Working with these clients, we continually push the boundaries of what is possible to do through technology, and in what time frame. Today, we are more than 5,000 experts across 20 countries. Together we form Nagarro, the global services division of Munich-based Allgeier SE.