What is the difference between MockMvc and WebTestClient?

♀尐吖头ヾ 提交于 2019-12-01 01:12:19

问题


When I tried to test at Spring 4.x, I used MockMvc web client, but I am reading and trying new features of Spring 5.x.

I think, WebTestClient and MockMvc are same or very similar.

What is the difference between MockMvc and WebTestClient ?

I am waiting for your answer. Thank you


回答1:


Similarities

  • Both provide a fluent-style syntax for testing web services.
  • Both can or do operate in a simulated environment that bypasses the use of HTTP.

Major Differences

  • WebTestClient can also be used to test real web services using HTTP.
    • Specify @SpringBootTest instead of @WebFluxText.
  • WebTestClient only works if you are using Netty for your local server.
    • This feels like an artificial limitation for the test environment.
    • It is likely due to the non-blocking nature of the underlying WebClient.
  • WebTestClient can test Streaming Responses

Resources

  • Benefits of having HTTP endpoints return Flux/Mono instances instead of DTOs
  • Unable to use reactive WebClient without spring-boot-starter-reactor-netty
  • WebTestClient documentation
  • Spring Boot Data Rest don't support reactive? -- limitations of Netty


来源:https://stackoverflow.com/questions/49330878/what-is-the-difference-between-mockmvc-and-webtestclient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!