Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 3.29 KB

File metadata and controls

20 lines (14 loc) · 3.29 KB

Various Approaches of Spring Controller Testing

This small repository provides some example Spring Boot Tests verifying the correct implementation of a very simple RestController. (If you are new to this topic, you can start with this "Building a RESTful Web Service" tutorial.)

The tests can be done with a manually wired MockMvc client or with a with a manually wired WebTestClient client.

If the class creation is under the control of Spring, the MockMvc client will by automatically wired and then can be run against a mocked servlet or an embedded server. Similar, WebTestClient client will by automatically wired and then can be run against a mocked servlet or an embedded server. (Both approaches are described here (mock environment) and here (running server).)

However, the straight-forward solution to test by MockMvc is to run a WebMvcTest. Correspondingly, the straight-forward solution to test by WebTestClient is to run a WebFluxTest.

In order to see all the tests succeeding, just check out and run mvn test.