SpringCloud 具有显式模式的WebFlux
2023-12-13 11:46 更新
另一种方法是在生成的测试中使用EXPLICIT
模式来使用WebFlux。
Maven.
<plugin> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-contract-maven-plugin</artifactId> <version>${spring-cloud-contract.version}</version> <extensions>true</extensions> <configuration> <testMode>EXPLICIT</testMode> </configuration> </plugin>
Gradle.
contracts {
testMode = 'EXPLICIT'
}
以下示例显示如何为Web通量设置基类和“确保休息”:
@RunWith(SpringRunner.class) @SpringBootTest(classes = BeerRestBase.Config.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "server.port=0") public abstract class BeerRestBase { // your tests go here // in this config class you define all controllers and mocked services @Configuration @EnableAutoConfiguration static class Config { @Bean PersonCheckingService personCheckingService() { return personToCheck -> personToCheck.age >= 20; } @Bean ProducerController producerController() { return new ProducerController(personCheckingService()); } } }
以上内容是否对您有帮助:
更多建议: