I’m using Maven 3.3.3 with Java 8 on Mac Yosemite. I have a bunch of integration tests and I have my failsafe plugin (v 2.18.1) set up as such …
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M -noverify -XX:-UseSplitVerifier ${itCoverageAgent}</argLine>
<skipTests>${skipAllTests}</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
However, when I run the command “mvn clean install,” even when I have failed unit tests, the build continues on to assembling the war. How do I prevent further Maven activity if I have failed integration tests? Below is example output of what I’m seeing. Note that the WAR plugin continues to run even after the tests have failed.
Results :
Failed tests:
MyProjectInstantLoginControllerIT.testInstantLoginSuccessNoCredentailsObj:245 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessStudent:153 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessTeacher:125 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
MyProjectInstantLoginControllerIT.testInstantLoginSuccessWithApacheHeader:187 View name is not equal to 'redirect:http://localhost:80/authenticate' but was 'redirect:http://localhost:80/home'
Tests in error:
ClassController2IT.testUpdateClassWoSchedule:478->AbstractClassControllerTest.submitCreateClassForm:514 » LazyInitialization
Tests run: 157, Failures: 4, Errors: 1, Skipped: 4
[INFO]
[INFO] --- maven-war-plugin:2.6:war (default-war) @ my-module ---
[INFO] Packaging webapp
[INFO] Assembling webapp [my-module] in [/Users/davea/Documents/my_workspace/my-module/target/my-module]
[INFO] Dependency [Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}] has changed (was Dependency {groupId=org.mainco.subco, artifactId=second-module, version=87.0.0-SNAPSHOT, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/second-module-87.0.0-SNAPSHOT.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}] has changed (was Dependency {groupId=org.springframework, artifactId=spring-core, version=3.2.11.RELEASE, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-core-3.2.11.RELEASE.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}] has changed (was Dependency {groupId=org.springframework.security.extensions, artifactId=spring-security-saml2-core, version=1.0.0.RC2, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/spring-security-saml2-core-1.0.0.RC2.jar] has not been found
[INFO] Dependency [Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}] has changed (was Dependency {groupId=org.opensaml, artifactId=opensaml, version=2.6.1, type=jar}).
[WARNING] File to remove [/Users/davea/Documents/my_workspace/my-module/target/my-module/WEB-INF/lib/opensaml-2.6.1.jar] has not been found
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/davea/Documents/my_workspace/my-module/src/main/webapp]
[INFO] Webapp assembled in [5454 msecs]
[INFO] Building war: /Users/davea/Documents/my_workspace/my-module/target/my-module.war
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:verify (default) @ my-module ---
[INFO] Failsafe report directory: /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:17 min
[INFO] Finished at: 2015-11-09T11:23:47-06:00
[INFO] Final Memory: 48M/792M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.18.1:verify (default) on project my-module: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/davea/Documents/my_workspace/my-module/target/failsafe-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
You haven't specified any phase(s) you want failsafe
plugin to run its goals on. By default, the goals integration-test
and verify
are bound to the integration-test
and verify
phases of the default
life cycle.
Recall that these phases occur after the package
phase is complete (refer the life cycle references), so with the configuration you have, you are not impacting the package
phase in any way - your goals run after the package
phase (i.e the goals set to run in that phase - the maven-war-plugin:2.6:war
being one) is complete.
You could try running the integration tests and verifying them before the package
phase if that's what you really want by specifying the appropriate phase(s) for your goals in the <execution>
you've shown in your OP.
Unrelated to the problem, the maven-failsafe-plugin
plugin is intended to target integration tests and decouple the build failures from the actual integration test results. You get around it by verifying your integration test results.
Here's a quote from the FAQ:
What is the difference between maven-failsafe-plugin and maven-surefire-plugin?
maven-surefire-plugin
is designed for running unit tests and if any of the tests fail then it will fail the build immediately.
maven-failsafe-plugin
is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.
Further notes on this subject:
If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly.
The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.