Skip to content

Instantly share code, notes, and snippets.

@dnno
Created December 21, 2022 09:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Spring JUnit5 style provider
@WebMvcTest
@Provider("UserServiceJUnit5")
@PactFolder("build/pacts")
public class PactProviderSpringJUnit5Test {
@TestConfiguration
static class Config {
@Bean
public UserRepository userRepo() {
return new UserRepository();
}
}
@Autowired
MockMvc mockMvc;
@Autowired
UserRepository userRepository;
@BeforeEach
public void setup(PactVerificationContext context) {
context.setTarget(new MockMvcTestTarget(mockMvc));
}
// 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