0

We are using PACT library for contract testing. Current project relies on junit5 integration. I have to extend one test to use 2 providers instead of 1:

Current version:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    public void myTestMethod() throws Exception {}

I read doc: https://docs.pact.io/implementation_guides/jvm/consumer/junit5 and it seems to be not supported yet:

Unsupported#

The current implementation does not support tests with multiple providers. This will be added in a later release.

I checked the release notes and I haven't found any updates. Is there another way how to define another provider? ie something as:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    @PactTestFor(providerName = "result-repository", hostInterface = "0.0.0.0", port = "9992")
    public void myTestMethod() throws Exception {}

Or in this case junit5 integration is not a good choice?

Lonestar
  • 51
  • 6

1 Answers1

2

My suggestion would be to write 2 separate tests, where each test has one provider mocked via Pact and the other provider stubbed out (e.g. with a standard unit test stub).

Matthew Fellows
  • 3,669
  • 1
  • 15
  • 18
  • Thx for the suggestion. It seems to be pretty easy to do. – Lonestar Oct 22 '20 at 06:19
  • That suggestion though doesn't work if you are testing a single business logic method that as part of its flow, talks to 2 providers, whose config is static (i.e. the port to use is defined before the test class executes). – Eric Mar 01 '23 at 19:20