I am testing my controller given below
@Controller
public class MasterController {
@GetMapping("/")
public String goLoginPage(){
return "index";
}
}
I am following this Spring documentation to test my controller. Now, I want to test my controller by just instantiating the web layer and not the whole Spring context as given in the documentation. Below is my code for the same.
@RunWith(SpringRunner.class)
@WebMvcTest
public class MasterControllerTestWithWebLayer {
@Autowired
MockMvc mockMvc;
@Autowired
MasterController masterController;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testLoginHome() throws Exception{
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(view().name("index"));
}
}
When I run this test I get the error Unable to find @SpringBootConfiguration,...etc
. But I am confused why it is asking for Spring configuration when we do not want it to instantiate it but want to use only the web layer. Kindly point me to the right direction what is happening here. And also how to fix this. Thanks