Quarkus Insights #117: Contract Testing with Pact and Quarkus
Dec 13, 2023
auto_awesome
In this discussion, Holly Cummins, a skilled software engineer, dives into the world of contract testing using Pact and Quarkus. She highlights how contract tests blend unit and integration testing for enhanced confidence in microservices. The conversation includes an intriguing demonstration involving a sweater shop application, showcasing the challenges of end-to-end testing. Holly also emphasizes the significance of consumer-driven contracts and efficient CI integration, ensuring robust software practices while navigating the complexities of HTTP response codes in testing.
Contract testing combines the lightness of unit tests with the confidence of integration tests, enhancing the development toolkit for microservices.
PACT serves as a consumer-driven contract testing tool that effectively manages dependencies in microservices, ensuring accurate interactions between services.
Maintaining effective feedback loops in microservices accelerates development cycles while improving code quality through early detection of integration problems.
Deep dives
Introduction to Contract Testing
Contract testing is a method designed to ensure that microservices work together correctly without requiring all services to be up and running simultaneously, thus avoiding the pitfalls of traditional testing. The discussion highlights the challenges posed by microservices, primarily their interdependencies, which can lead to failures when changes are made to one service without considering its interactions with others. It introduces the concept of using contract testing to mitigate these issues by establishing clear agreements between services about how they communicate, ultimately promoting more robust development practices. The approach encourages teams to focus on both consumer and provider roles to maintain effective collaboration and streamline the integration process.
The Role of PACT in Contract Testing
PACT is presented as a consumer-driven contract testing tool that addresses the complexities of managing dependencies in microservices architecture. It clarifies that while mocks can simulate the behavior of services, they may not accurately represent the actual interactions, which can lead to false positives in tests. By contrast, PACT generates contracts that can be validated against the provider, ensuring that the system's components adhere to expected behavior. As a result, teams gain confidence that their microservices can work together seamlessly, even as individual services evolve independently.
Decoupling Microservices with Effective Feedback Loops
The podcast emphasizes the importance of maintaining effective feedback loops in microservices to shorten development cycles and ensure that changes do not break the system. It illustrates how traditional testing methods can lead to long delays in identifying issues, which ultimately hinders development speed and quality. By using tools like PACT, teams can develop shorter and more efficient testing processes that allow them to detect integration problems earlier in the development cycle. This proactive approach not only improves code quality but also enhances collaboration among teams working on different microservices.
Overcoming Common Microservices Challenges
The discussion reveals common challenges encountered in microservices architectures, such as coupling issues, making assumptions about service behavior, and difficulties in maintaining system coherence as services evolve. It recounts real-world experiences where small changes in one microservice inadvertently led to system-wide failures due to overlooked dependencies or misalignments. Highlighting practical examples, the podcast underscores the importance of thorough testing and communication between teams to avoid these pitfalls. Contract testing with tools like PACT helps teams catch these issues before they escalate, fostering a culture of accountability among service providers and consumers.
The Future of Testing with PACT and Quarkus
The podcast concludes with insights into the ongoing development of contract testing tools, particularly PACT's integration with Quarkus, showcasing its readiness for production use. Participants discuss their plans to enhance the PACT Quarkus extension, which aims to simplify implementation and reduce boilerplate code for developers. The conversation also touches on the importance of community feedback in further refining these tools and adapting them to meet evolving industry needs. As contract testing continues to gain traction, the collaboration between consumers and providers will be pivotal in propelling software development efficiencies in the microservices landscape.
Holly Cummins discusses how contract tests combine the lightness of unit tests with the confidence of integration tests, and should be part of your development toolkit.
Introduction to contract-first:
https://www.redhat.com/en/blog/achieving-promise-microservices-one-contract-time
A tutorial on doing contract-first using an OpenAPI approach:
https://appdev.consulting.redhat.com/tracks/contract-first/
The documentation for the JVM binding for Pact:
https://docs.pact.io/implementation_guides/jvm
The Pact Quarkus extension:
https://github.com/quarkiverse/quarkus-pact
The sample code:
https://github.com/holly-cummins/pact-quarkus-sweater-demo
Get the Snipd podcast app
Unlock the knowledge in podcasts with the podcast player of the future.
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode
Save any moment
Hear something you like? Tap your headphones to save it with AI-generated key takeaways
Share & Export
Send highlights to Twitter, WhatsApp or export them to Notion, Readwise & more
AI-powered podcast player
Listen to all your favourite podcasts with AI-powered features
Discover highlights
Listen to the best highlights from the podcasts you love and dive into the full episode