我有一个包含两个模块的 Maven 项目,一个用于生产者,另一个用于消费者。
Project
-- Producer module
-- Consumer module
消费者包含对生产者 stub 的依赖,即
<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 在本地运行测试,则找不到 stub 并且测试失败。
这是项目结构的问题吗?如果是这样,我可以更改一些内容以使其在不更改代码的情况下运行吗?
最佳答案
类路径在 ide 中无法工作,例如Intellij 不会将 stub jar 添加到类路径中。这是 ides 的一个已知问题。
关于java - Spring Cloud Contract 测试适用于 Maven,但不适用于 JUnit 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60706001/