Quarkus Pact Provider

This extension ensures Pact provider libraries works well with Quarkus applications, including with continuous testing. It is based on version 4.6.14 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>1.4.2</version>
    <scope>test</scope>
</dependency>

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

  • @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)

Samples and resources