What is the difference between MockMvc and WebTestClient?

后端 未结 1 936
北恋
北恋 2021-01-02 02:00

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 o

相关标签:
1条回答
  • 2021-01-02 02:30

    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 @WebFluxTest.
    • 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
    0 讨论(0)
提交回复
热议问题