- 在pom.xml中加入Junit及整合用的相关依赖
<!--Junit单元测试框架-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- Spring-Test是Spring与Junit提供的整合包
通过这个组件可以在Junit测试时自动对IOC容器进行初始化
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
//根据需要(发生ClassNotFound异常时)加入其它依赖包,加上<scope>test</scope>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<!-- scope = test 代表只在单元测试时才会加载这个依赖 -->
<scope>test</scope>
</dependency>
- 使用:在对应src下面的类中按快捷键 (atl+insert),选择test即可。