package com.uas.platform.b2c; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; 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.transaction.annotation.Transactional; import org.springframework.web.context.WebApplicationContext; /** * Spring MVC 测试基类,所有测试类继承自这个类就可以直接写单元测试 * @author stg * @date 2017年11月8日16:48:18 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:spring/context.xml") @WebAppConfiguration("") @Transactional @TransactionConfiguration(defaultRollback = true) public class BaseJunitTest { @Autowired protected WebApplicationContext wac; protected MockMvc mockMvc; /** * 前置防范,配置MVCMock */ @Before public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); } }