Unit testing

Let's quickly write a unit test checking for the JSON response and then add the test to BasicControllerTest:

    @Test    fun `GET welcome-with-object returns "Hello World"`() {      mvc.perform(      MockMvcRequestBuilders.get("/welcome-with-object")      .accept(MediaType.APPLICATION_JSON))      .andExpect(status().isOk())      .andExpect(content().string(      containsString("Hello World")));    }

This test is very similar to the earlier unit test, except that we are using containsString to check whether the content contains an "Hello World" substring.

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.