Take a look at the examples in the Spring reference manual referring to using MockMvc to test server-side code. Assuming you are returning a JSON response:
mockMvc.perform(get("/index"))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$.greeting").value("Hello World"));
By the way - never catch and swallow an exception in a @Test
method, unless you want to ignore that exception and prevent it from failing the test. If the compiler is complaining that your test method called a method that throws an exception and you didn't handle it, simply change your method signature to throws Exception
.