1、测试的代码片段
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-mvc.xml","classpath:spring-mybaties.xml"})
@WebAppConfiguration
//如果是true不会改变数据库数据,如果是false会改变数据
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback = false)
public class TestSSM {
@Autowired
private CommonController commonController;
@Autowired
ServletContext context;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(commonController).build();
}
@Test
public void controllerExceptionHandler() throws Exception {
ModelAndView postJson = commonController.getAllUser();
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/getAllUser.do"))
.andExpect(MockMvcResultMatchers.view().name("user/view"))
.andExpect(MockMvcResultMatchers.model().attributeExists("user"))
.andDo(MockMvcResultHandlers.print())
.andReturn();
Assert.assertNotNull(result.getModelAndView().getModel().get("user"));
}
}
2、遇到的问题
当我引用此项依赖时,会出现一个错误
详细的介绍,请移步下面的url
http://sishuok.com/forum/blogPost/list/7981.html