我在尝试为返回Thymeleaf视图的简单ViewResolver
方法编写单元测试时遇到异常。
听起来我需要指定@Controller
public class LoginController {
@RequestMapping(value = {"/", "/login"}, method = RequestMethod.GET)
public ModelAndView login() {
return new ModelAndView("login");
}
}
,但不知道该怎么做。
的LoginController
@RunWith(SpringRunner.class)
public class LoginControllerTest {
private MockMvc mockMvc;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.standaloneSetup(new LoginController())
.build();
}
@Test
public void testLoginPage() throws Exception {
this.mockMvc.perform(get("/login"))
.andExpect(status().isOk())
.andExpect(view().name("login"))
.andDo(print());
}
}
LoginControllerTest
javax.servlet.ServletException: Circular view path [/login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
错误
fromCallable