契约 Spring/JUnit5、"At least one pact source must be present on the test class"

Pact Spring/JUnit5, "At least one pact source must be present on the test class"

我正在尝试使用 Pact/Junit5 创建契约验证测试。 这是我开始的例子:

@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();
    }
}

合同文件位于“src/test/resources/pacts”
但我收到此错误:

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

使用 Pact 版本 4.1.7

仔细检查您导入的 @PactFolder 注释是否正确。

import au.com.dius.pact.provider.junitsupport.loader.PactFolder;

我认为这是由于不幸的命名冲突导致的问题。