对于聚合工程下是放到启动类所处模块的test下进行的,这是因为如果在对应的module下无法获取到启动类,如果进行单元测试,需要在test下新建一个启动测试类和application.properties,这样才可以,如果整个项目都是自己写的话,那就没必要单独的在子模块下进行单元测试了,直接在启动类所在的web模块的test下进行就可以
1.利用Spring initializr创建出的springboot,pom中会自带spring-boot-test依赖。
如果是用maven创建的,需要手动在父工程中引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
2.测试类上方用两个注解
@Runwith(SpringRunner.class)代表用谁去执行
@SpringBootTest(classes=引导类.class)
3.属性上方用@Autowired
4.方法上方用@Test