MockMvc单元测试的ViewResolver异常

时间:2017-03-16 16:10:55

标签: java spring unit-testing junit

我在尝试为返回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

0 个答案:

没有答案