Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

[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?

like image 904
dingalla Avatar asked May 05 '13 18:05

dingalla


People also ask

What is Maven Fail Safe?

maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.

How do I exclude test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

How do you ignore an integration-test?

The -DskipTests will skip the execution of both unit tests (surefire) and integration tests (failsafe). In order to just skip the integration tests, we can pass the -DskipITs system property. Finally, it's worth mentioning that the now-deprecated flag -Dmaven. test.

How do I run an integration-test in Maven?

The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.


2 Answers

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> 
like image 148
pro-tester Avatar answered Oct 21 '22 14:10

pro-tester


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

like image 22
Raymond Avatar answered Oct 21 '22 13:10

Raymond