[英]How to validate Exception in spring-webflux WebTestClient tests?
[英]WebTestClient does not work when using spring-webflux
我正在通過Spring Boot 2.0.0.M3使用Spring webflux。 以下是我項目的依賴關系,
dependencies {
compile 'org.springframework.boot:spring-boot-starter-actuator',
'org.springframework.cloud:spring-cloud-starter-config',
'org.springframework.cloud:spring-cloud-sleuth-stream',
'org.springframework.cloud:spring-cloud-starter-sleuth',
'org.springframework.cloud:spring-cloud-starter-stream-rabbit',
'org.springframework.boot:spring-boot-starter-data-mongodb-reactive',
'org.springframework.boot:spring-boot-starter-data-redis-reactive',
'org.springframework.boot:spring-boot-starter-integration',
"org.springframework.integration:spring-integration-amqp",
"org.springframework.integration:spring-integration-mongodb",
'org.springframework.retry:spring-retry',
'org.springframework.boot:spring-boot-starter-webflux',
'org.springframework.boot:spring-boot-starter-reactor-netty',
'com.fasterxml.jackson.datatype:jackson-datatype-joda',
'joda-time:joda-time:2.9.9',
'org.javamoney:moneta:1.0',
'com.squareup.okhttp3:okhttp:3.8.1',
'org.apache.commons:commons-lang3:3.5'
compileOnly 'org.projectlombok:lombok:1.16.18'
testCompile 'org.springframework.boot:spring-boot-starter-test',
'io.projectreactor:reactor-test',
'org.apache.qpid:qpid-broker:6.1.2',
'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
}
通過./gradlew bootRun
或直接運行主應用程序,該應用程序運行良好。
但是由於以下錯誤,我無法啟動集成測試。
引起原因:org.springframework.boot.web.server.WebServerException:無法啟動嵌入式Tomcat
我想知道為什么即使我們使用默認情況下使用反應式網絡的webflux, WebTestClient仍然嘗試使用嵌入式tomcat。
這是配置錯誤還是Spring Boot測試錯誤?
下面是我的測試用例的代碼片段,
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class NoteHandlerTest {
@Autowired
private WebTestClient webClient;
@Test
public void testNoteNotFound() throws Exception {
this.webClient.get().uri("/note/request/{id}", "nosuchid").accept(MediaType.APPLICATION_JSON_UTF8)
.exchange().expectStatus().isNotFound();
}
}
啟動tomcat的錯誤是由測試依賴項org.apache.qpid:qpid-broker:6.1.2
,該依賴項取決於javax.serlvet-api:3.1
中斷了tomcat的啟動。
排除以下使Tomcat重新啟動的無用模塊,
configurations {
all*.exclude module: 'qpid-broker-plugins-management-http'
all*.exclude module: 'qpid-broker-plugins-websocket'
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.