🪴 Nishanth Gobi

Testing in SpringBoot

Apr 11, 20241 min read

  • zettel
  • lit

WebMvcTest

@RunWith(SpringRunner.class)
@WebMvcTest(HelloController.class)
public class HelloControllerApplicationTest {
    @Autowired    
    private MockMvc mvc;
 
    @Test
    public void getHello() throws Exception {
        mvc.perform(
	        MockMvcRequestBuilders.get("/")
	    )
	    .andExpect(status().isOk())
        .andExpect(
	        content().string(equalTo("Hello!"))
		);
    }
}

Refs

  1. https://stackoverflow.com/questions/39865596/difference-between-using-mockmvc-with-springboottest-and-using-webmvctest

Graph View

Created with Quartz v4.5.2 © 2026

  • GitHub
  • X
  • LinkedIn