srping mvc 单元测试

来源:互联网 发布:python 入门gui 编辑:程序博客网 时间:2024/06/05 11:38

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

0 0
原创粉丝点击