Search code examples
spring-bootmaven-surefire-plugin

default surefire not executing the test with Spring Boot


I am working on a quite simple Spring Boot 2.4.2 project, using the BOM :

  <dependency>
    <!-- Import dependency management from Spring Boot -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>2.4.2</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>
</dependencies>

when running mvn clean verify, I get this : we see that no test is found by Surefire 2.12.4

[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ api-testing --- 
[INFO] Surefire report directory: C:\Users\vincent\IdeaProjects\api-testing\target\surefire-reports

-------------------------------------------------------  T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

I don't understand why.. I tried several things, and even if it's not recommended, I tried overriding the version by adding this in my pom :

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.2</version>
    </plugin>
  </plugins>
</build>

And now my test is found !

[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ api-testing ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running de.vincent.AssetReferentialServiceTest

I am really surprised by this Spring Boot behavior - I assume I am missing something.. but what ?

Note : my test is a Junit 5 test, and I have no Junit 4 related jars in my classpath - only Junit Jupiter 5.7.0 and Junit platform 1.7.0

Thanks


Solution

  • Thanks a lot @M. Deinum for pointing out the issue in the comment.

    Of course, using Spring Boot parent pom helps a lot in using the proper plugins versions !

    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.4.2</version>
    </parent> 
    

    The BOM will only help for the dependencies, not the build plugins.