Maven fail-safe not executing tests

僤鯓⒐⒋嵵緔 提交于 2019-11-30 05:43:20

You need to rename your test class.

You can find the names the plugin looks for by default in the documentation, as pointed out by @acdcjunior:

By default, the Failsafe Plugin will automatically include all test classes with the following wildcard patterns:

  • "**/IT*.java" - includes all of its subdirectories and all java filenames that start with "IT".
  • "**/*IT.java" - includes all of its subdirectories and all java filenames that end with "IT".
  • "**/*ITCase.java" - includes all of its subdirectories and all java filenames that end with "ITCase".

I had a similar problem. If there aren't any test classes compiled to target/test-classes then check your pom file and ensure that the packaging isn't 'pom'.

For multi-module projects, the child project needs to have the plugin declared as followed,

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
 </plugin>

version inherits from parent pom. Without the above defined, the plugin in parent pom alone will not work.

Your tests are not in the default test sources directory src/test/java. See:

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

myModule/src/main/test/java/ClientAccessIT.java

should be:

myModule/src/test/java/ClientAccessIT.java

You could also update your pom file (if you really wanted tests to live in main) to include:

<build>
    <testSources>
        <testSource>
            <directory>src/main/test</directory>
        </testSource>
    </testSources>
</build>

I also had a similar problem but needed the packaging element to be "pom". Make sure your test source files are being compiled and added to the .../target/test-classes folder using the maven-compiler-plugin:

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.version}</version>
            <executions>
                <execution>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

I was having the same issue and tried a few of the suggested options here. I am developing a Spring Boot application using JUnit 5. Unfortunately, none of my integration tests (located in src/test/java and suffixed with *TestIT.java) were getting picked up, regardless of the advertising of the plugin to do so. I tried downgrading to 2.18.1, 2.19.1 and tried both removing the <executions> and <configuration> sections to attempt to use even the plugin's default functionality, but no luck.

I finally changed the version to the latest (as of the time of writing) to 2.22.0, and viola. Here is the configuration I added to the <build><plugins> section of my pom. And even better, I don't need to add executions that define the integration-test and verify goals that you see most people include; failsafe executes these by default. I've included my surefire plugin configuration as well, since I am using it to execute unit tests during the test phase of the maven lifecycle.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.0</version><!--$NO-MVN-MAN-VER$-->
</plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.22.0</version><!--$NO-MVN-MAN-VER$ -->
</plugin>

And just for good measure, to tell surefire and failsafe to use JUnit 5, I am including this in my <dependencies> section:

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-engine</artifactId>
  <scope>test</scope>
</dependency>

Eclipse displays a warning (yellow squiggly underline) under the version tag, hence the inclusion of the <!--$NO-MVN-MAN-VER$ --> error. I'm sure there's a better way to deal with this, but it works for me in this case.

To speed up testing this configuration, and to avoid having to go through all of the earlier lifecycle phases before test, integration-test orverify phases, I used the following commands to quickly validate:

  • mvn failsafe:integration-test (runs only integration tests)
  • mvn surefire:test (runs only unit tests)
  • (I obviously run the entire lifecycle when it counts)

Hope this helps someone. Cheers!

For me it was a missing executions section

            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>

The failsafe with TestNG documentation at https://maven.apache.org/surefire/maven-failsafe-plugin/examples/testng.html had shown a pom without it, and it didn't work.

<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>3.0.0-M3</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    [...]
</plugins>

Adding the missing executions section shown above solved the problem.

I had somewhat similar issue. My Integration tests were not being picked up. My project is a multi module spring boot project. And my mistake was that I added maven-failsafe-plugin in the parent POM. After fiddling around with many options I placed the failsafe-plugin in the module pom where all my integration tests were present which solved my problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!