How to run integration test of a spring-boot based application through maven-failsafe-plugin?

Here is a document for

Spring Boot Maven Plugin
Last Published: 2021-01-22| Version: 2.5.x

It says

While you may start your Spring Boot application very easily from your test (or test suite) itself, it may be desirable to handle that in the build itself. To make sure that the lifecycle of you Spring Boot application is properly managed around your integration tests, you can use the start and stop goals as described below:

<build>
  ...
  <plugins>
    ...
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>2.0.2.RELEASE</version>
      <executions>
        <execution>
          <id>pre-integration-test</id>
          <goals>
            <goal>start</goal>
          </goals>
        </execution>
        <execution>
          <id>post-integration-test</id>
          <goals>
            <goal>stop</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

For who not familiar with integration test, I found this answer also quite helpful.


Since my application is based on Spring-Boot, and spring-boot-maven-plugin is included in pom.xml, so what I need to do is to add following configuration to make sure the lifecycle of our Spring Boot application is well managed around.

<executions>
  <execution>
    <id>pre-integration-test</id>
    <goals>
      <goal>start</goal>
    </goals>
  </execution>
  <execution>
    <id>post-integration-test</id>
    <goals>
      <goal>stop</goal>
    </goals>
  </execution>
</executions>

Then when I issue mvn clean verify, the spring boot application will be running with our integration test code.