Skip to content

Instantly share code, notes, and snippets.

@dnno
Created December 21, 2022 09:19
Show Gist options
  • Save dnno/c4d4a1f2b2c6853aeab3f1177b638b44 to your computer and use it in GitHub Desktop.
Save dnno/c4d4a1f2b2c6853aeab3f1177b638b44 to your computer and use it in GitHub Desktop.
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