Maven fail-safe not executing tests

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Maven fail-safe not executing tests



I've combed StackOverflow and many other sites, have found many other related posts and have followed all said suggestions, but in the end, failsafe is skipping my tests.



My JUnit test is located here:
myModule/src/main/test/java/ClientAccessIT.java


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



I am skipping surefire because there are no unit tests in this module:


<!-- POM snippet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>



And I'm trying to run integration tests with failsafe:


<!-- POM snippet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>run-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>



However, when I run mvn verify I see this:


mvn verify


[INFO] --- maven-failsafe-plugin:2.14.1:integration-test (run-tests) @ rest-services-test ---

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

Results :

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



I spent the last 4 1/2 hours scouring, any help would be appreciated. The only other thing that may be worth mentioning is that I have Cargo setting up and tearing down a Tomcat container. Does anybody see the glaring problem?



D




6 Answers
6



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


**/*IT.java


**/*ITCase.java





That does not seem to be true: maven.apache.org/surefire/maven-failsafe-plugin/examples/… - it says the default patterns are **/IT*.java, **/*IT.java, **/*ITCase.java.
– acdcjunior
May 5 '13 at 20:17




**/IT*.java


**/*IT.java


**/*ITCase.java





@acdcjunior beat me to it; here's a direct link to the relevant documentation page: maven.apache.org/surefire/maven-failsafe-plugin/…
– kryger
May 5 '13 at 20:21







"**/*IT.java" - includes all of its subdirectories and all java filenames that end with "IT". Wouldn't ClientAccessIT.java meet the qualifications of this pattern?
– danny-v
May 5 '13 at 23:01







It's the little things... forgot to decorate with @Test...
– danny-v
May 5 '13 at 23:12





The example "ClientAccessIT.java" clearly matches *IT.java. So this answer is just useless and confusing.
– Gustave
Feb 15 '17 at 6:50



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'.





Thanks. That was the problem for me. Not at all obvious!
– Quintin Willison
Dec 2 '15 at 9:37



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.





This was the solution for me. failsafe was defined in the parent->parent POM.
– Amoeba
Jan 13 '17 at 16:57



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>





Strangely my packaging was jar but test classes were not compiled. Thanks.
– Vitaly Sazanovich
Oct 12 '16 at 14:46





This was my issue also, as soon as I included compiler plugin integration tests started working!
– Leon
Sep 22 '17 at 10:14



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.


src/test/java


*TestIT.java


<executions>


<configuration>



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.


<build><plugins>


integration-test


verify


test


<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:


<dependencies>


<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.


<!--$NO-MVN-MAN-VER$ -->



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:


test


integration-test


verify


mvn failsafe:integration-test


mvn failsafe:integration-test


mvn surefire:test



Hope this helps someone. Cheers!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived