您的问题是与Maven生命周期有关。根据的文档,默认情况下,
spring-boot:run它绑定到lifecyle阶段
validate,并
test-compile在执行之前调用该阶段。
您要求的是在运行应用程序之前 执行 测试。您可以使用POM中的自定义Maven配置文件来执行此操作-类似于以下内容。
<project> <profiles> <profile> <id>test-then-run</id> <build> <defaultGoal>verify</defaultGoal> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <id>spring-boot-run</id> <phase>verify</phase> <goals> <goal>run</goal> </goals> <inherited>false</inherited> </execution> </executions> </plugin> </plugins> </build> </profile> ... </profiles>...</project>
在您的POM中使用此功能之后,您可以运行测试并通过以下方式启动应用程序:
mvn -P test-then-run
这将
run目标绑定到
verify阶段而不是
validate阶段,这意味着将首先运行测试。您可以在此处查看运行阶段的顺序:https : //maven.apache.org/ref/3.3.9/maven-
core/lifecycles.html



