- Maven项目的pom.xml文件的依赖jar包
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.25.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
- 单元测试JUnit基本测试类demo
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring.xml","classpath:spring-mvc.xml","classpath:spring-mybatis.xml"})
@WebAppConfiguration
public class TestBase {
protected MockMvc mockMvc;
protected MockHttpServletRequest request;
protected MockHttpServletResponse response;
@Autowired
protected WebApplicationContext wac;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(this.wac)
.alwaysDo(MockMvcResultHandlers.print())
.build();
request = new MockHttpServletRequest();
request.setCharacterEncoding("UTF-8");
response = new MockHttpServletResponse();
}
}