Created
December 21, 2022 09:19
-
-
Save dnno/c4d4a1f2b2c6853aeab3f1177b638b44 to your computer and use it in GitHub Desktop.
Spring JUnit5 style provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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