Mastery of Mocking is Critical for Testing Modern API-driven Applications

Mastery of Mocking is Critical for Testing Modern API-driven Applications

API Mocking is Critical for testing Modern API-Driven Applications

The complexity and variety of service interactions is increasing in modern applications. Most applications today are architected as a collection of API-driven services. In the extreme, we are also witnessing a rise in the adoption of microservices. There are many reasons for an increase in adoption. However, this also has spawned an additional burden of “service testing” for engineering teams.

Service tests are good for early (even pre-submit) validation of integration with other microservices – validating new functionality as well as identifying regressions in existing functionality. Each service test issues a request and compares the actual response (or elements within the response) with the expected response. All regression requests to upstream services are mocked for the test. Thus, service tests can be run independently for each service, and potentially on a developer’s laptop. The following picture illustrates the service tests for a microservice “Order Service” which depends on upstream microservices “Order Details” and “Payments” (which are mocked).

No alt text provided for this image

Service Tests Enable Shift Left

The following test pyramid evangelized by Martin Fowler has been widely recognized as the ideal scenario in the context of distributed and micro-services architectures. It is important to focus on service tests to quickly and easily identify service integration issues. The ability to create and run these service tests as easily as unit tests is becoming critical for engineering teams.

No alt text provided for this image

API Mocking is at the Centre of Service Testing

Challenges

  •    Ability to use API mocks and live services for ad hoc service testing during development
  •   Creating a rich set of API mocks for all regression requests
  •   Coordination between producers and consumers of APIs to update API mocks so tests reflect reality as soon as possible. If this isn’t done right, service tests lose the benefit of shifting the integration testing left.
  •   Extensive effort needed to update service tests and regression API mocks whenever upstream APIs change even slightly.

Ideal API Mocking Solution

For Adhoc service testing, it is critical for developers to be able to use a mix of live services and API mocks, and to easily customize mocks.

For automated service testing

  • Ability to easily create API mocks
  • Ability to alert when API mocks need to be updated
  • Ability to update the API mocks with little effort
  • Improve development velocity by enabling engineers to develop and debug in their IDE as though the entire application is running locally, and eliminating many of the inefficiencies in microservices development processes.
  • Speed up the creation of API integration tests for microservices components and applications by learning API tests from manual testing activity over the application UI
  • Enable developers to run relevant CI tests before code submit, minimizing late detection of failures in CI.
  • Reduce the costs incurred in provisioning and maintaining dev clusters by reducing the need for dev cluster during development. Costs can become significant for larger teams.

As always, Bhaskar clearly and concisely illuminates important thoughts about systems testing in a way that helps practitioners and leaders keep them in the forefront ""Yes, of course!" I thought as I read through this article -- but the contribution is that I am now thinking about it. An challenge that seems significant to me that Bhaskar didn't mention explicitly is to avoid forgetting that a service test has been mocked when the actual service is available! Perhaps another article could explore means to try to overcome that challenge.

Like
Reply

Very informative. Thanks for sharing your insights

Very good write up and nicely articulated!!

Very good write up. Excellent

Quite useful Information. Thanks for Sharing!

Like
Reply

To view or add a comment, sign in

More articles by Bhaskar P.

  • Embracing the Multi-Cloud Strategy: Benefits and Best Practices for Organizations

    In recent years, the multi-cloud strategy has emerged as a transformative approach to managing IT infrastructure and…

    8 Comments
  • Automation using Ansible

    Source: Javapoint Introduction Automation has become a must-have technology to respond to change. Organizations that…

    4 Comments
  • Test Data Management (TDM) on Cloud

    Introduction Test Data Management (TDM) is the process of planning, designing, storing and managing data that benefits…

    23 Comments

Others also viewed

Explore content categories