You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pact提供者测试出现InitializationError,消费者可正常上传契约

契约测试初始化错误排查问题

同一台机器上,消费者侧可成功将契约上传至PactFlow Broker,但运行提供者契约测试时出现初始化错误,日志如下:

2023-03-03 09:52:35.575  INFO 22944 --- [           main] c.a.c.c.test.FaturaOdemeContractTest     : Started FaturaOdemeContractTest in 8.261 seconds (JVM running for 15.164)
org.junit.runners.model.InitializationError
    at au.com.dius.pact.provider.junit.PactRunner.checkIgnoreIoException(PactRunner.kt:130)
    at au.com.dius.pact.provider.junit.PactRunner.initialize(PactRunner.kt:99)
    at au.com.dius.pact.provider.junit.PactRunner.getChildren(PactRunner.kt:152)
    at org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426)
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:85)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
2023-03-03 09:53:18.082  INFO 22944 --- [       Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2e8e8225: startup date [Fri Mar 03 09:52:28 EET 2023]; root of context hierarchy
2023-03-03 09:53:18.086  INFO 22944 --- [       Thread-2] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2023-03-03 09:53:18.088  INFO 22944 --- [       Thread-2] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2023-03-03 09:53:18.088  INFO 22944 --- [       Thread-2] o.s.i.channel.PublishSubscribeChannel    : Channel 'application:0.errorChannel' has 0 subscriber(s).
2023-03-03 09:53:18.088  INFO 22944 --- [       Thread-2] o.s.i.endpoint.EventDrivenConsumer       : stopped _org.springframework.integration.errorLogger
2023-03-03 09:53:18.089  INFO 22944 --- [       Thread-2] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'

推测JUnitRunner无法找到测试用例,怀疑是防火墙或认证问题,参考相关资料后未解决。


相关配置信息

提供者依赖配置

<dependency>
      <groupId>au.com.dius.pact.provider</groupId>
      <artifactId>spring</artifactId>
      <version>4.1.41</version>
      <scope>test</scope>
        <exclusions>
            <!-- 不排除该依赖时,会出现guava未找到的问题 -->
          <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

消费者上传契约的Maven插件配置

<plugin>
            <groupId>au.com.dius.pact.provider</groupId>
            <artifactId>maven</artifactId>
            <version>4.1.17</version>
            <configuration>
                <pactBrokerUrl>https://akbank.pactflow.io</pactBrokerUrl>
                <pactBrokerToken>MyToken</pactBrokerToken>
            </configuration>
        </plugin>

提供者JUnit测试类注解配置

@PactUrl(
    urls="https://akbank.pactflow.io/pacts/provider/fatura-service/consumer/Mobil Mudurluk Fatura Ekibi/latest", 
    auth = @Authentication(token = "MyToken"))

本地测试特殊情况

使用@PactFolder("pacts")时测试可正常运行,但必须依赖au.com.dius:pact-jvm-provider-spring_2.12:3.5.24版本,否则会出现Gson方法找不到异常。


内容的提问来源于stack exchange,提问作者Cagin Uludamar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 11:56:36