Reputation: 2687
We have the following config in our POM file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
This ensures that the tests are not executed during test phase. Tests are executed only during integration-test phase.
However, when we prepare for release (release:prepare), maven executes the tests during test phase. This causes our build to fail because our tests can be run only during Integration test phase (we use tomcat-maven plugin to deploy the packaged war before the tests can be executed).
I know that we can skip the tests by passing the parameter (-DskipTests etc.). We do not want to skip any tests, we just want release:prepare to execute just like any other maven goal.
Any suggestion/help is highly appreciated.
Upvotes: 3
Views: 4323
Reputation: 26743
Use the maven-failsafe-plugin
for the integration tests, and keep maven-surefire-plugin
for the unit tests.
This will guarantee that the unit tests are completely segregated from the integration tests (and can therefore be turned off separately), and the integration tests are run during the "integration-test
and verify
phases of the build lifecycle".
Upvotes: 3
Reputation: 48045
Try with the more general approach to disable the maven-surefire-plugin
completely during test
phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<!-- Disable the default-test by putting it in phase none -->
<phase>none</phase>
</execution>
<execution>
<!-- Enable the test during integration-test phase -->
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
Edit
This is the output from my dry run of mvn release:prepare
with the above configured surefire plugin:
C:\Users\maba\Development\svn\local\stackoverflow\Q12840869>mvn release:prepare -DdryRun [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-release-plugin:2.0:prepare (default-cli) @ Q12840869 --- [INFO] Resuming release from phase 'scm-check-modifications' [INFO] Verifying that there are no local modifications... [INFO] Executing: cmd.exe /X /C "svn --non-interactive status" [INFO] Working directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869 [INFO] Checking dependencies and plugins for snapshots ... What is the release version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.0: : What is SCM release tag or label for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) Q12840869-1.0: : What is the new development version for "Q12840869-1.0-SNAPSHOT"? (com.stackoverflow:Q12840869) 1.1-SNAPSHOT: : [INFO] Transforming 'Q12840869-1.0-SNAPSHOT'... [INFO] Not generating release POMs [INFO] Executing preparation goals - since this is simulation mode it is running against the original project, not the rewritten ones [INFO] Executing goals 'clean verify'... [WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance. [INFO] [INFO] Scanning for projects... [INFO] [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] Building Q12840869-1.0-SNAPSHOT 1.0-SNAPSHOT [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] [INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ Q12840869 --- [INFO] [INFO] Deleting C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target [INFO] [INFO] [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ Q12840869 --- [INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] [INFO] Copying 0 resource [INFO] [INFO] [INFO] [INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ Q12840869 --- [INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\classes [INFO] [INFO] [INFO] [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ Q12840869 --- [INFO] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] [INFO] skip non existing resourceDirectory C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\src\test\resources [INFO] [INFO] [INFO] [INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q12840869 --- [INFO] [INFO] Compiling 1 source file to C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\test-classes [INFO] [INFO] [INFO] [INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ Q12840869 --- [INFO] [INFO] Building jar: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\Q12840869-1.0-SNAPSHOT.jar [INFO] [INFO] [INFO] [INFO] --- maven-surefire-plugin:2.7.2:test (surefire-it) @ Q12840869 --- [INFO] [INFO] Surefire report directory: C:\Users\maba\Development\svn\local\stackoverflow\Q12840869\target\surefire -reports [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.stackoverflow.MainTest [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.041 sec [INFO] [INFO] Results : [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] BUILD SUCCESS [INFO] [INFO] ------------------------------------------------------------------------ [INFO] [INFO] Total time: 5.102s [INFO] [INFO] Finished at: Thu Oct 11 17:10:29 CEST 2012 [INFO] [INFO] Final Memory: 13M/147M [INFO] [INFO] ------------------------------------------------------------------------
Upvotes: 2
Reputation: 139921
I would try an alternate approach, and try to configure the release plugin to always use -DskipTests
as an argument so you don't need to specify it each time:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin<artifactId>
<configuration>
<arguments>-DskipTests</arguments>
</configuration>
</plugin>
In theory this should append -DskipTests
to the arguments that the prepare
and release
goals pass to the sub-executions of Maven that they execute.
Upvotes: 3
Reputation: 32587
Add your integration tests in a separate profile which isn't active by default. Add a triggerring rule or something. Then invoke the builds with the integration tests on a need by need basis. For example, on your CI (Jenkins/Hudson, TeamCity, Bamboo, etc) triggered the profile.
The problem you are currently facing is that you haven't made a separation between the two types of tests and when they should run. You have simply defined the phases you would like them to execute in. This isn't sufficient knowledge of the execution context for Maven to figure out what you would like to do and it invokes them during the release as well.
Upvotes: 2