Quarkus Pact Provider

This extension ensures Pact provider libraries works well with Quarkus applications, including with continuous testing. It is based on version 4.3.17 of the Pact JVM JUnit 5 library.

Installation

To use this extension, add the io.quarkiverse:quarkus-pact-provider extension first to your build file. Choose a 1.x version for Quarkus 3, and a 0.x version for Quarkus 2.

<dependency>
    <groupId>io.quarkiverse</groupId>
    <artifactId>quarkus-pact-provider</artifactId>
    <version>0.2.1</version>
    <scope>provided</scope>
</dependency>

Note the provided scope, rather than test or default. This is needed for the tests to pass in continuous testing mode.

Example usage

Use Pact as you normally would. For example, a simple provider test for REST endpoints would look like this:

@Provider("Farm") (1)
@PactFolder("pacts")
@QuarkusTest
public class SimpleContractTest {

    (2)
    @ConfigProperty(name = "quarkus.http.test-port")
    int quarkusPort;

    @BeforeEach
    void before(PactVerificationContext context) {
        context.setTarget(new HttpTestTarget("localhost", quarkusPort)); (3)
    }

    @TestTemplate (4)
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }
}
1 Add @Provider annotations to the class, along with instructions where to find the pacts (a folder or a broker).
2 We inject Quarkus configuration.
3 With the injected configuration, we can tell the Pact verifier where to look for our endpoints.
4 Standard Pact provider boilerplate, to create a series of templated tests which run the Pact verifications.

Extension Configuration Reference

For the moment, Pact needs to be configured by the normal Pact system properties.

Known limitations

  • If continuous testing is being used, the dependency scope cannot be test. The provided scope is a good alternative.ps

  • @State methods do not not have access to the CDI context (GitHub issue)

  • When changing the code of classes with a @TestTemplate, continuous testing may not automatically retrigger (Fix PR)

  • @TestProfile does not work in dev mode (GitHub issue)

  • A harmless java.lang.NoClassDefFoundError: org/apache/hc/client5/http/fluent/Request message will be produced if Pact tracking is enabled (GitHub issue)

Samples and resources