Integration testing

The code to perform integration testing on the TodoController class is shown in the following code snippet. It launches up the entire Spring context with all the controllers and beans defined:

   @RunWith(SpringJUnit4ClassRunner.class)   @SpringBootTest(classes = Application.class, webEnvironment =        SpringBootTest.WebEnvironment.RANDOM_PORT)   public class TodoControllerIT {    @LocalServerPort    private int port;    private TestRestTemplate template = new TestRestTemplate();    @Test    public void retrieveTodos() throws Exception {     String expected = "["     + "{id:1,user:Jack,desc:\"Learn Spring MVC\",done:false}" + ","     + "{id:2,user:Jack,desc:\"Learn Struts\",done:false}" + "]";     String uri = "/users/Jack/todos"; ResponseEntity<String> response ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.