【问题标题】:how can I do an Unit Test below code using WebFlux and Java 8?如何使用 WebFlux 和 Java 8 在代码下方进行单元测试?
【发布时间】:2019-01-31 09:28:18
【问题描述】:

我想使用 WebFlux 创建一个单元测试这段代码,但我不知道怎么做,我需要在单元测试中覆盖下面的 100% 调用方法。

@Autowired
private WebClient webClient;

public String call(final String xml) {
    return this.webClient.post().uri("URL")
                         .contentType(MediaType.APPLICATION_XML)
                         .body(Mono.just(xml),String.class)
                         .retrieve()                             
                         .bodyToMono(String.class)
                         .block();
}

非常感谢谁能帮助我

【问题讨论】:

标签: unit-testing spring-boot spring-webflux


【解决方案1】:

您不能真正对此进行单元测试,您必须进行集成测试。启动您自己的 Web 服务器,提供有助于您的测试的内容。至少这是我唯一的想法。

在这里看看这个:

https://mock-server.com/mock_server/running_mock_server.html

【讨论】:

    【解决方案2】:

    如果您想对此进行单元测试,最好使用像mockito 这样的库来模拟WebClient,但是该函数看起来更值得进行集成测试,因为您实际上只是在测试模拟的功能点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-29
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多