繁体   English   中英

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

[英]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;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM