您还没有启用自动配置,这些会用来通过PersonControllerTest
的配置,这意味着它的Groovy模板支撑春天启动的自动配置不会发生。要解决该问题,请将@EnableAutoConfiguration
添加到ControllerTestConfig
。
它实际上并没有与1.1.7.RELEASE一起工作,但它的失败方式与您的测试无法识别的方式不同。
如果您更新的测试也叫MockMvcResultHandlers.print()
:
…
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {Content-Type=[text/html;charset=UTF-8]}
Content type = text/html;charset=UTF-8
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
如果添加@EnableAutoConfiguration
如上所述:
mockMvc.perform(get("/persons/"));
.andDo(print())
.andExpect(status().isOk())
.andExpect(view().name("persons/list"))
.andExpect(model().attribute("persons", hasSize(1)));
你会在响应具有空体输出看到,响应将包含预期的HTML:
…
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {Content-Type=[text/html;charset=UTF-8]}
Content type = text/html;charset=UTF-8
Body = <!DOCTYPE html><html class='no-js' lang='en'><head></head><body><h2>Person list</h2><table><thead><tr><th>Name</th><th>Surname</th></tr></thead><tr><td/><td/></tr></table></body></html>
Forwarded URL = null
Redirected URL = null
Cookies = []
如果您具有可重现性测试用例,在GitHub上针对Spring Boot提出错误。 – chrylis 2014-10-05 21:48:33