SpringMvc测试
添加mvn依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.6.RELEASE</version>
<scope>test</scope>
</dependency>
创建普通测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CourageConfig.class)
public class NormalTest{
}
创建controller层测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {CourageConfig.class, DispatcherConfig.class})
@WebAppConfiguration
public class WebTest{
}