Search code examples
javaspring-bootjunit5pact

How to pass multiple consumer names in pact provider JUnit test


Using the pact provider JUnit 5/Spring Boot support annotations, perhaps I am not searching well for the answer... I'm wondering if it's possible to annotate a pact provider verification test with multiple consumers using the @Consumer annotation.

Like I would want to be able to do something like the following

@Provider("provider-name")
@Consumer("consumer-1, consumer-2")
@PactBroker
@ActiveProfiles("test")
public class PactVerificationTest {

    @Test
    //test methods
    //...
}

The annotation takes a String as a value so unfortunately something like @Consumer({"consumer-1", "consumer-2"}) does not work either.


Solution

  • Like this:

    @PactBroker(consumerVersionSelectors = {
            @VersionSelector(consumer = "my-consumer-1"),
            @VersionSelector(consumer = "my-consumer-2")
    })
    

    Use the latest library version and see documentation for more