Skip to content

Instantly share code, notes, and snippets.

@dnno
Created December 21, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnno/d05134fb03f9763e80da2f3fe8c03b5f to your computer and use it in GitHub Desktop.
Save dnno/d05134fb03f9763e80da2f3fe8c03b5f to your computer and use it in GitHub Desktop.
JUnit5 style pact provider test
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Provider("UserServiceJUnit5")
@PactFolder("build/pacts")
public class PactProviderJUnit5Test {
@LocalServerPort
int port;
@BeforeEach
public void setup(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", port));
}
// see: https://docs.pact.io/getting_started/provider_states
@State("A running user service")
void setupUserService() {
// no state setup ATM
}
@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment