我用Spring Cloud Contract为HTTP编写了一个非常简单的合同测试。我创建了在/ src / test / resources / contracts下具有合同定义的生产者:
package contracts
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'GET'
url '/documents/123456789'
headers {
contentType('application/json')
}
}
response {
status OK()
body([
id : 123456789,
status: "VALID"
])
headers {
contentType('application/json')
}
}
}
生产者是一个具有以下定义的Maven模块:
<groupId>com.sample</groupId>
<artifactId>rest-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest-producer</name>
我只将此生产者部署到我的Maven本地存储库中。之后,我创建了一个依赖于生产者存根的使用者:
<dependency>
<groupId>com.sample</groupId>
<artifactId>rest-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>stubs</classifier>
<scope>test</scope>
</dependency>
并且我定义了一个简单的测试,该测试使用类路径搜索存根:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = "com.sample:rest-producer:+:stubs:8080")
class DocumentReaderIntTest {
...
}
当我通过全新安装使用maven build运行此测试时,一切正常。但是,当我尝试通过Intellij的RunConfiguration运行此测试时,出现一个异常,找不到存根。我应该如何设置才能使此测试在Intellij上正常工作?
编辑: 我发现的是,当我仅打开使用者项目时,然后在类路径中它具有来自本地Maven存储库的jar:
/Users/adam/.m2/repository/com/sample/rest-producer/0.0.1-SNAPSHOT/rest-producer-0.0.1-SNAPSHOT-stubs.jar
但是,当我在同一项目中导入生产者时,它使用类路径中的target / classes文件夹,因此找不到合同定义:
/Users/adam/projects/rest-producer/target/classes
答案 0 :(得分:0)
是的,这是Intellij的一个已知问题。当您在多模块项目中引用类路径依赖项时,Intellij不会构建存根jar,而是直接引用其他模块的代码。也许向Intellij提出问题会有意义吗?