MICROSERVICES
TESTING
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
End to end testing
Integration
testing Contract
testing
Unit testing
Exploratory testing
Scope
of
testing
Execution
time
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.
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 Free open source version and Pro Version
Rest- Assured Open source
Postman Open source
SOAtest API Open source
PRACT
PACTO
Janus Contract Testing Open source
AppDynamics Free 14-day Trial, then from $230 monthly.
TraceView $39.50/host/month
NewRelic Monitoring Free plan, then from $149 per month.
Jmeter Open source
NeoLoad Performance Licensed
Loadrunner testing 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.
Read - https://www.swtestacademy.com/microservices-testing-strategies/
Conclusion

microservice testing tools and technologies

  • 1.
  • 2.
    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.
  • 3.
    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.
  • 4.
    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
  • 5.
    Microservices testing types UI testing Endto end testing Integration testing Contract testing Unit testing Exploratory testing Scope of testing Execution time Number of tests
  • 6.
    • 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
  • 7.
    • 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. 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
  • 8.
    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
  • 9.
    • 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
  • 10.
    • 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
  • 11.
    Tools to test microservices ToolType of Testing Type of License SOAP UI Free open source version and Pro Version Rest- Assured Open source Postman Open source SOAtest API Open source PRACT PACTO Janus Contract Testing Open source AppDynamics Free 14-day Trial, then from $230 monthly. TraceView $39.50/host/month NewRelic Monitoring Free plan, then from $149 per month. Jmeter Open source NeoLoad Performance Licensed Loadrunner testing 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. Read - https://www.swtestacademy.com/microservices-testing-strategies/ Conclusion