@EntendWith(SpringExtenstion.class)
//to focus on mvc components only
@WebMvcTest(ClassNameYoureGoingToTest.class)
class HelloControllerIntegrationTest{
@Autowired
private MockMvc mvc;
@Test
void hello() throws Exception{
RequestBuilder request = MockMvcRequestBuilders.get("/find/by/id");
MvcResults result = mvc.perform(request).andReturn();
//first param is expected value, second- actual value
assertEquals("Hello, World", results.getResponse().getContentAsString());
}
@Test
public void testHelloWithName throws Exception{
mvc.perform(get("/find/by/id?id=123")).andExpect(content().string("Hello, Dan"));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter