首页 > 解决方案 > 向协议代理发布验证结果在 pact-jvm-provider-spring_2.12 中不起作用

问题描述

我正在尝试使用 pact for jvm/spring 将验证结果发布给 pact broker。我正在使用junit4。测试执行并通过,验证报告打印到控制台/添加 json 文件,但它没有将结果发布到协议代理。

在 pom.xml 中:

<dependency>
    <groupId>au.com.dius</groupId>
    <artifactId>pact-jvm-provider-spring_2.12</artifactId>
    <version>3.5.24</version>
</dependency>

在 TestContract.class 中:

@RunWith(SpringRestPactRunner.class)
@Provider("prov_test")
@PactBroker(host="192.168.132.220",port="80")
@VerificationReports({"console", "json"})
@SpringBootTest(
    properties={
        "pact.provider.version=1.0.1",
        "pact.verifier.publishResults=true"
    },
    webEnvironment = SpringBootTest.webEnvironment.DEFINED_PORT
)
public class TestContract {
...
...
}

在输出中,我收到警告:

Skipping publishing of verification results (pact.verifier.publishResults is not set to 'true')

谢谢你的帮助!

标签: springspring-bootpact

解决方案


我们是junit5,必须在@BeforeEach 中设置它才能让它工作:

    void setupTestTarget(PactVerificationContext context) {
        context.setTarget(new HttpTestTarget("localhost", port, "/"));
        System.setProperty("pact.verifier.publishResults", "true");
        System.setProperty("pact.provider.version", buildVersion);
    }

推荐阅读