Webinar: Solving the Integration Testing Puzzle with Contract Testing [Voices Of Community]

Saniya Gazala

Posted On: September 29, 2023

view count9076 Views

Read time13 Min Read

In today’s world of digital changes, businesses are increasingly dependent on interconnected software systems. To ensure these systems work well, we need solid and efficient ways to test them. Traditional integration and end-to-end testing approaches have struggled to keep pace with the demands of today’s distributed systems. It can lead to problems like delays, frustrating deployment issues, and unreliable applications. To tackle these issues, contract testing has emerged as a powerful solution that promises to revolutionize how we ensure software component’s integrity and compatibility.

Digital transformation is a significant topic today, and contract testing is vital in making it happen. Watch the webinar for complete insights on implementing contract testing and its common approaches.

In case you missed the webinar, here are the key highlights of the event discussing contract testing as a potential solution for addressing the difficulties associated with integration and end-to-end testing in modern distributed systems. We will also learn how it can enhance testing strategies with the practical implementation of contract testing.

About the Webinar

Bas Dijkstra started by addressing what contract testing is?. He clarified that contract testing serves as a supplementary testing approach rather than a substitute for functional API. He further emphasizes that contract testing tools like Rest Assured, Postman, or Karate should be integrated into the existing testing process. It is positioned to replace traditional integration and end-to-end testing methods executed with tools such as Selenium, Cypress, or Playwright. He advised that contract testing complements and enhances the overall testing strategy rather than completely replacing existing testing tools and practices.

voices of community

Integration Testing Challenges

Bas further explained the significance of integration and end-to-end testing in distributed software development. He highlights the primary challenge in ensuring effective communication between individual components and services within a system, significantly when separate teams or organizations develop these components.

challenges

He further illustrated this challenge with an example of a provider service that manages addresses and how it is tested separately by its team. When the consumer of this service, such as an order management service, has different expectations, it can lead to conflicts and defects. It emphasizes the importance of aligning the expectations of other components.

challenges example

With this example, he points out that all components were traditionally tested in a single system. Still, as systems become more distributed, this approach becomes increasingly complex and resource-intensive. Configuring and managing test environments under these circumstances can become a full-time job. This is where contract testing comes in.

test environments

What is Contract Testing?

Contract testing is particularly good at uncovering conflicts of interest between components. It helps discover differences in expected behavior and actual behavior. By testing the contracts between components, we can ensure that all the services can communicate effectively.

contract testing

Traditional Testing vs Contract Testing

Contract testing and traditional testing are two distinct approaches to ensure the quality and functionality of software systems. He further compared contract testing and Traditional based on crucial aspects:

Key Aspects Traditional Testing Contract Testing
Scope Encompasses end-to-end and integration testing, often involving the entire system or a significant portion of it. Focuses on individual parts of consumers and providers, examining the contracts between them.
Purpose Targets overall system behavior, assessing how different components work together.

Primarily aimed at verifying that consumers and providers adhere to their agreed-upon contracts, ensuring compatibility at a micro-level.
Synchronization Typically synchronous, requiring both consumer and provider to be in the same environment and actively communicate during testing. Asynchronous, allowing consumers and providers to test independently in their local development and deployment processes.
Granularity Often involves coarser-grained testing, covering broader functionality and interactions. Emphasizes fine-grained testing, focusing on specific contract interactions and expectations.
Testing Tools Employs a variety of tools, including Selenium, Cypress, and others, for integration and end-to-end testing. Utilizes specialized tools like Pact and Spring Cloud Contract, tailored for contract testing.
Integration Challenges Encounter challenges when ensuring effective communication between components, especially in distributed systems. Well-suited for uncovering conflicts of interest and differences in behavior between components.
Responsibility Typically involves a centralized testing effort and may require extensive team coordination.

It often falls under the responsibility of both consumer and provider teams, with consumers defining and validating expectations.

To summarize the comparison, he made it simpler for better understanding, stating that contract testing focuses on specific interactions and contracts between components, offering more particle and asynchronous approaches. It helps uncover compatibility issues between consumers and providers.

Traditional testing, on the other hand, encompasses broader system behavior, making it suitable for end-to-end and integration testing but potentially more labor-consuming.

He further said that the choice between these approaches depends on the testing needs and the nature of the software system being developed.

Benefits of Contract Testing

Contract testing offers several benefits, including conflict resolution, compatibility enhancement, faster issue resolution, micro-level assurance, streamlined testing, improved collaboration, reduced testing overhead, and early issue detection. Let’s learn a bit more about each of the mentioned benefits by Bas Dijkstra.

  • Conflict Resolution: Contract testing identifies conflicts between components. It also helps reveal the differences in expectations, facilitating early issue resolution in development.
  • Compatibility Enhancement: By inspecting contracts between components, contract testing ensures that different services can communicate effectively. This compatibility helps in reducing integration issues during deployment.
  • Faster Issue Resolution: It enables quick identification of disagreements between expected and actual behavior and accelerates issue identification and resolution, saving valuable development time.
  • Micro-Level Assurance: It verifies that individual component interaction sticks to specified contracts. This level of detail enhances the reliability of the software ecosystem.
  • Streamlined Testing Process: It operates asynchronously and independently for consumers and providers, simplifying the testing process and helping teams validate their components without complex synchronization efforts.
  • Improved Collaboration: Contract testing involves consumer and provider teams defining and validating contracts. This collaborative approach enhances better team communication and alignment, encouraging a shared understanding of system behavior.
  • Reduced Testing Overhead: It can reduce the need for extensive end-to-end and integration testing. It can lead to a more efficient testing process, lowering the overall testing overhead.
  • Early Issue Detection: Identifying issues at the contract level enables early detection and resolution of potential integration problems. This approach contributes to smoother software development and deployment.

These advantages make it a valuable addition to the testing strategies for modern software development.

Contract Testing Approaches

Bas stated that there are three different approaches to contract testing: consumer-driven, provider-driven, and bidirectional. He further gave a small statement for each of these approaches to see how these approaches work.

Contract Testing Approaches

  • Consumer-driven approach: In this approach, the consumer defines their expectations for the provider’s behavior within a contract, and the provider subsequently validates these expectations.
  • Provider-driven approach: In this approach, contract testing takes the reverse approach, where the provider communicates its behavior to the consumer, and it’s the consumer’s responsibility to verify this behavior.
  • Bidirectional approach: In this approach, both the consumer and provider present their expectations to a third party. This third party then examines these expectations for discrepancies or integration issues.

He further shared his blog for more in-depth details on different approaches to contract testing.

He mentions that he will primarily focus on the widely used consumer-driven approach. Nevertheless, it is essential to consider which approach is best suited for your specific context before implementing contract testing.

To understand contract testing better watch the following video given below

Consumer-driven approach

The consumer-driven approach is a method within contract testing where the service consumer defines what they expect from the service provider’s behavior. This expectation is documented in a contract detailing the anticipated interactions and responses from the provider.

Consumer-driven approach

The provider then validates its implementation to ensure it aligns with the consumer’s contract, ensuring that the consumer’s needs are met and that the provider behaves as expected. This approach enhances the collaboration of the consumer and provider team, strengthening the overall system’s reliability.

In further sessions, he explained the commonly used tools for contract testing. Let’s discover the tools that can help perform contract testing.

Contract Testing Tools

He further said several tools, including Pact and Spring Cloud Contract, are available for contract testing.

  • Pact: It is a cross-platform library that supports multiple programming languages, making it a popular choice.
  • Spring Cloud Contract: It is limited to Java and the Spring ecosystem.

Further in this session, he delves into the mechanics of Pact and its application in consumer-driven contract testing.

How does a Pact work to generate a contract?

He further progressed, explaining the workings of Pact in a very detailed manner. He started explaining how we can create contracts using Pact.

Pact follows a process involving consumer-side tests. These tests serve a dual purpose: they validate that the consumer’s implementation functions correctly as intended and simultaneously produce a contract. This contract is then used to generate a mock provider that mimics the behavior expected by the consumer. It enables testing of the consumer’s implementation by utilizing the predefined responses from the mock provider.

produce a contract

The crucial step in this process is the contract’s generation, which can be shared with the provider. On the provider’s side, Pact generates a mock consumer. It replays all the interactions outlined in the contract and verifies whether the responses provided by the actual provider align with the expectations defined in the contract. This thorough process ensures the contractual commitments are fulfilled.

Contract Testing Workflow

He explained that contract testing workflow encompasses various stages, including distribution, management, version control, and storage of contracts. Typically, this is facilitated through a Pact broker. Two versions of the Pact broker are available: an open-source variant provided as a Docker image and a cloud-based alternative named Pactflow.

In further demonstration, he highlighted Pactflow, a commercial product. It utilizes the free plan, eliminating the need for payment or credit card details.

Contract Testing Workflow

In the contract testing process, the consumer initiates by generating and publishing a contract, while the provider follows by downloading and validating compliance with this contract. Subsequently, both parties employ a tool called “Can I Deploy” to assess potential integration issues during their development and deployment phases.

Live Implementation of Code and Explanation

In this section, Bas has given an overview of his code and further delves into the concept of bidirectional contract testing. He progressed, explaining that this approach involves the consumer and provider actively participating in contract testing by creating contracts to specify expected behaviors and interactions. While Pact is a commonly used tool for consumer-side contract testing, Bas introduces an alternative approach for consumers. Instead of relying on Pact, consumers can generate their contracts from interactions using WireMock, an HTTP mocking tool.

Live Implementation of Code and Explanation

This approach leverages the “yMock Pact Generator,” an extension for WireMock, which listens to requests and responses during tests and automatically generates consumer-side contracts. Moreover, this approach allows for the generation of arrangements for the primary interaction between the consumer and the provider and for interactions with supplementary services, such as a payment provider.

These contracts are subsequently published to a contract broker like Pactflow, which verifies their compatibility, ensuring that expectations align with the actual behavior of the services.

Pactflow

This streamlined process simplifies contract testing, enhances collaboration between teams, and helps maintain contract consistency. To know more, follow the GitHub repo on introduction to contract testing.

Bidirectional Contracts

He further progressed, explaining that bidirectional contract testing is an alternative to the consumer-driven approach. It relies on Pactflow, not Pact, and involves consumers and providers contributing contracts. Pactflow acts as a contract broker, verifying compatibility.

Bidirectional Contracts

The downside of bidirectional contract testing is that the comparisons performed by the broker could be more detailed compared to consumer-driven contract testing. Unlike consumer-driven testing, which allows for particular expectations, bidirectional contract testing, mainly when using Pactflow, relies on what is generated or found in the contracts.

It often means that the matching is limited to confirming the presence of elements and verifying if the data types align with what each side expects. At the same time, bidirectional testing is more straightforward to initiate.

It was a great session on contract testing and how these approaches can help resolve the challenges faced while performing integration and end-to-end testing.

He wrapped up the session by answering some of the questions.

Q & A Session

Q: If this can only be used for HTTP GETs or for all other types of interactions

Bas: Yes, it works with all HTTP requests like DELETE, UPDATE, PUT, and POST. There are some working examples. In short, it works with other types of interactions as well.

Q: Can contract test code be utilized for API request validation purposes?

Bas: Yes, using contract test code for API request validation is possible. However, it may not be the best practice because ensuring that the consumer and provider meet their respective expectations is typically the responsibility of their respective teams. The consumer team should ensure their outputs align with expectations, while the provider team should verify their service meets those expectations. Using contract testing for both purposes may blur these responsibilities. Employing other testing methods within the respective teams for clarity and efficiency is advisable.

Q: How can we integrate contract testing with tools like PACT without sidelining our existing investments?

Bas: Contract testing is not meant to replace all existing testing methods but to enhance them by focusing on specific aspects of compatibility and integration. Integrating it wisely with your current testing tools and practices can help you achieve a more robust and efficient testing process.

I hope You Enjoyed The Webinar!

I hope you found this webinar on “Solving the Integration Testing Puzzle with Contract Testing” insightful. In case you missed it, you can find the webinar recording above. Share this valuable webinar with those interested in mastering contract testing for integration challenges. Stay tuned for more LambdaTest Webinar. You can also subscribe to our newsletter, Coding Jag, to stay on top of informative webinars, testing challenges, and more!

That’s all for now. Happy contract testing!

Author Profile Author Profile Author Profile

Author’s Profile

Saniya Gazala

Saniya Gazala is a Computer Science graduate from Reva University. She began as a manual tester, honing her skills in defect identification and problem-solving. Transitioning to technical writing, she simplified complex tech concepts for users. Her journey is marked by continuous learning and growth in the tech industry.

Blogs: 13



linkedintwitter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free