Pact Spring/JUnit5,“测试类中必须至少存在一个 Pact 源”

dro*_*one 4 java pact

我正在尝试使用 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();
    }
}

Run Code Online (Sandbox Code Playgroud)

合同文件位于“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
Run Code Online (Sandbox Code Playgroud)

使用 Pact 版本 4.1.7

Mat*_*ows 6

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

import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
Run Code Online (Sandbox Code Playgroud)

我认为这由于不幸的命名冲突而引起了问题。