Spring Cloud Contract测试可以与Maven一起使用,但在与JUnit一起运行时不能使用



我有一个Maven项目,它有两个模块,一个用于生产者,另一个用于消费者。

Project
-- Producer module
-- Consumer module

使用者包含对生产者存根的依赖,即

<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在本地运行测试,则找不到存根,测试就会失败。

这是关于项目结构的问题吗?如果是这样的话,我是否可以在不更改代码的情况下更改某些内容以使其运行?

Classpath将无法从ide中工作,例如Intellij没有将stubs jar添加到类路径中。这是ide的一个已知问题。

最新更新