欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring mvc 3.2 测试  

程序员文章站 2022-06-08 13:25:40
...
@ContextConfiguration(locations = {"classpath:spring-config.xml","classpath:dispatcher-servlet.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = true)
public class BaseTest {
}


public class AcctUserActionTest extends BaseTest {

    @Resource
    private AcctUserAction acctUserAction;

    @Test
    public void testSaveUser() throws Exception {
        // 执行URI对应的action
        MockMvc mockMvc = MockMvcBuilders.standaloneSetup(acctUserAction).build();
        ResultActions ra = mockMvc.perform(MockMvcRequestBuilders
                .post("/user/saveUser")
                .accept(MediaType.APPLICATION_JSON)
                .param("username", "xxx")
                .param("password", "123123")
                .param("lastLoginDate", "2012-12-12")
                .param("lastLoginIp", "127.0.0.1"));
        MvcResult mr = ra.andReturn();
        String result = mr.getResponse().getForwardedUrl();
        Assert.assertEquals("/common/success",result);
     }

    
}


spring mvc 3.2  测试