Search code examples
javamavenjunitmaven-surefire-plugin

Maven surefire plugin doesn't find unit tests


  • Yes, the Java classes which are containing the tests are named correctly. (they are ending with Tests)
  • Tried to add the following configuration in pom.xml:

     <configuration>
            <includes>
                <include>**/*Test.java</include>
            </includes>
        </configuration>

  • Tests are located under the following structure: /src/test/packagename/JavaClassTest.java where packagename is the same package what is under the unit test written under src/main/java path.
  • I'm using jupiter Junit 5 and maven-surefire-plugin with 2.22.2

And I still get the following error on mvn test:


    --- maven-surefire-plugin:2.22.2:test (default-test) @ <project-name> ---
    [INFO] No tests to run.

What do I do wrong?


Solution

  • Is there any reason why you configure just a certain tests? By default the surefire plugin should access all classes in testRoot and sub directories.

    You could also just link a specific file like

    src/test/ArchTest.java

    to see if it is the "include" in your configuration or something else. I am not sure that the wildecards are working as you expect them to work. See Maven <include> wildcard match on partial folder name . Based on this you might try out

     <configuration>
          <includes>
              <include>/**/*Test.java</include>
          </includes>
      </configuration>