配置及创建流程
1.pom文件配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
2.在需要测试的方法上
右键->Go to->Test
会自动创建测试方法,包括包路径映射都是一样的

3.看测试文件夹已经生成好了

@SpringBootApplication 需要自己手动添加,可以用来测试Service方法等。
4.特别注意:
自动生成的测试包路径与源代码路径包名是完全对应的,可以自动识别到启动类。
如果自己手动创建包名及测试类,若包名与源代码不一致,则在@SpringBootApplication中需指定启动类
@SpringBootApplication(classes = {ApiApplication.class})
网友评论