春季云契约测试在Maven中运行正常,但在使用JUnit运行时却不起作用。

huangapple go评论71阅读模式
英文:

Spring Cloud Contract tests work with Maven but not when run with JUnit

问题

我有一个包含两个模块的Maven项目,一个用于生产者,另一个用于消费者

项目
-- 生产者模块
-- 消费者模块

消费者模块包含对生产者存根的依赖,即:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>producer-application</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <classifier>stubs</classifier>
    <scope>test</scope>
</dependency>

集成测试配置为,StubRunner 使用类路径扫描,即:

@AutoConfigureStubRunner(
        stubsMode = StubRunnerProperties.StubsMode.CLASSPATH,
        ids = "com.example:producer-application:+:8090"
)

在构建过程中,消费者模块的集成测试可以正确执行,但是如果我尝试通过IDE(IntelliJ)本地运行JUnit测试,存根将无法找到,导致测试失败。

这是否是项目结构的问题?如果是,我是否可以在不更改代码的情况下使其运行?

英文:

I have a Maven project with two modules, one for the producer and another for consumer.

Project
-- Producer module
-- Consumer module

The consumer contains a dependency to the producer stubs, i.e.

<dependency>
    <groupId>com.example</groupId>
    <artifactId>producer-application</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <classifier>stubs</classifier>
    <scope>test</scope>
</dependency>

and the integration tests are configured so StubRunner uses classpath scanning, i.e.

@AutoConfigureStubRunner(
        stubsMode = StubRunnerProperties.StubsMode.CLASSPATH,
        ids = "com.example:producer-application:+:8090"
)

During build, the integration tests for the consumer are executed correctly but if I try to run the tests locally with JUnit through the IDE (IntelliJ), the stubs are not found and tests fail.

Is this an issue on how the project is structured? If so, is there something I can change to have it run without changing the code?

答案1

得分: 0

Classpath在IDE中不起作用,因为例如Intellij不会将存根(stubs)JAR添加到类路径中。这是IDE中已知的问题。

英文:

Classpath will not work from ide cause e.g. Intellij does not add the stubs jar to the classpath. It's a known issue with the ides.

huangapple
  • 本文由 发表于 2020年3月16日 20:25:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/60706001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定