package com.zzy.wyxtools.user.controller; import com.zzy.SysApplication; import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import javax.transaction.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @SpringApplicationConfiguration(classes = SysApplication.class) //当然 你可以声明一个事务管理 每个单元测试都进行事务回滚 无论成功与否 @TransactionConfiguration(defaultRollback = true) @Transactional public class IndexControllerTest extends TestCase { @Autowired private WebApplicationContext wac; private MockMvc mockMvc; @Before public void setUp() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } @After public void tearDown() throws Exception { } @Test public void testIndex() throws Exception { mockMvc.perform((post("/login").param("abc", "def"))) .andExpect(status().isOk()).andDo(print()); mockMvc.perform((post("/index").param("abc", "def"))) .andExpect(status().isOk()).andDo(print()); } @Test public void testGetBaseUrl() throws Exception { } @Test public void testGetRequest() throws Exception { } @Test public void testGetResponse() throws Exception { } @Test public void testRenderValidateImg() throws Exception { } @Test public void testSaveSysUserToSession() throws Exception { } @Test public void testRemoveSysUserSession() throws Exception { } @Test public void testGetCurrentSysUser() throws Exception { } @Test public void testValidPassword() throws Exception { } @Test public void testEntryptPassword() throws Exception { } @Test public void testPageParamResolve() throws Exception { } @Test public void testSaveQueryInfoAndReturnPage() throws Exception { } @Test public void testSaveQueryInfoAndReturnPage1() throws Exception { } @Test public void testSaveRequestParameter() throws Exception { } @Test public void testBackList() throws Exception { } @Test public void testSaveSysActionLog() throws Exception { } @Test public void testGetCurrentUser() throws Exception { } @Test public void testQuotaChange() throws Exception { } @Test public void testQuotaChange1() throws Exception { } }
Spring MVC 单元测试
最新推荐文章于 2022-04-11 19:05:22 发布