问题描述
我有一个Kotlin和JUNIT 5设置。并且在从Spring Cloud合同生成片段时遇到了问题。也许有人给我一些提示。
我还有一个带有RouterHandler的Webflux Netty安装程序
示例在我的github https://github.com/marzelwidmer/kboot-puername
上Spring boot版本:2.3.3.RELEASE Spring Cloud版本:Hoxton.SR8 Spring Cloud Contract版本:2.2.4.RELEASE
mvn install
结果
└── target
├── classes
├── generated-sources
├── generated-test-sources
├── jacoco.exec
├── kboot-puername-0.0.0-stubs.jar
├── kboot-puername-0.0.0.jar
├── kboot-puername-0.0.0.jar.original
├── kotlin-ic
├── maven-archiver
├── maven-status
├── site
├── stubs
├── surefire-reports
└── test-classes
我的Maven配置。
<!-- Contracts -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
<!-- Remember to add this for the DSL support in the IDE and on the consumer side -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-spec-kotlin</artifactId>
<scope>test</scope>
</dependency>
<!-- Used For Spring Contracts with WEBTESTCLIENT testMode -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-web-test-client</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-webtestclient</artifactId>
<scope>test</scope>
</dependency>
<!-- Contracts -->
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<testFramework>junit5</testFramework>
<testMode>WEBTESTCLIENT</testMode>
<!-- <testMode>EXPLICIT</testMode>-->
<baseClassForTests>
ch.keepcalm.demo.contract.PersonRestBase
</baseClassForTests>
<failOnInProgress>false</failOnInProgress>
</configuration>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<dependencies>
<!-- Contract Spec Kotlin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-spec-kotlin</artifactId>
<version>${spring-cloud-contract.version}</version>
</dependency>
</dependencies>
</plugin>
我的基础课:
@AutoConfigureRestDocs(outputDir = "target/snippets")
@AutoConfigureWebTestClient
@AutoConfigureJsonTesters
@DirtiesContext
@ExtendWith(RestDocumentationExtension::class,SpringExtension::class)
abstract class PersonRestBase {
@BeforeEach
fun setup() {
RestAssuredWebTestClient.webTestClient(WebTestClient.bindToRouterFunction(
apiPersons()
).build())
}
private fun apiPersons(): RouterFunction<ServerResponse> = router {
"api".nest {
GET("/persons") {
ok().contentType(MediaType.APPLICATION_JSON)
.body<Any>(Flux.just(PersonDocument(firstName = "John")))
}
}
}
}
以下内容也无济于事
@BeforeEach
fun setup(restDocumentation: RestDocumentationContextProvider?) {
RestAssuredWebTestClient.webTestClient(WebTestClient.bindToRouterFunction(
apiPersons()
).configureClient()
.filter(documentationConfiguration(restDocumentation))
.build())
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)