I'm trying to create a pact verification test with Pact/Junit5. This is the example I started with:
@Provider("myAwesomeService")
@PactFolder("pacts")
class MockMvcTestTargetStandaloneMockMvcTestJava {
@BeforeEach
void before(PactVerificationContext context) {
MockMvcTestTarget testTarget = new MockMvcTestTarget();
testTarget.setControllers(new DataResource());
context.setTarget(testTarget);
}
@RestController
static class DataResource {
@GetMapping("/data")
@ResponseStatus(HttpStatus.NO_CONTENT)
void getData(@RequestParam("ticketId") String ticketId) {
}
}
@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
}
}
The contract file is located in "src/test/resources/pacts"
but I'm getting this error:
14:53:30.452 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - provideTestTemplateInvocationContexts called
14:53:30.456 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - Verifying pacts for provider 'myAwesomeService' and consumer 'null'
14:53:30.456 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - Pact source on test class: null
14:53:30.726 [main] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider - Pact loaders on test class: []
java.lang.UnsupportedOperationException: At least one pact source must be present on the test class
Using Pact version 4.1.7
Double check that you're importing the right @PactFolder
annotation.
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
I think this has caused issues due to an unfortunate naming conflict.