5 Replies Latest reply on Mar 6, 2010 11:53 AM by alrubinger

    Maven Failsafe Plugin

    alrubinger

      http://www.sonatype.com/people/2009/06/integration-tests-with-maven-part-1-failsafe-plugin/

      http://mojo.codehaus.org/failsafe-maven-plugin/

       

      Came across this today via a Tweet from Jeremy Norris.

       

      What I don't yet understand is how this is much different from configuring Surefire, as I do now in the EJB Book Examples:

          <profile>
      
            <!-- Declare the "Integration Test" Profile -->
            <id>it</id>
            <activation>
              <activeByDefault>true</activeByDefault>
            </activation>
      
            <build>
      
              <plugins>
      
                <!--
      
                  Configure Surefire to run in integration-test phase
                -->
                <plugin>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <executions>
                    <execution>
                      <id>surefire-it</id>
                      <phase>integration-test</phase>
                      <goals>
                        <goal>test</goal>
                      </goals>
                      <configuration>
                        <skip>false</skip>
                        <redirectTestOutputToFile>true</redirectTestOutputToFile>
                        <printSummary>true</printSummary>
                        <forkMode>always</forkMode>
                        <includes>
                          <include>**/*IntegrationTestCase.java</include>
                        </includes>
                      </configuration>
                    </execution>
                  </executions>
                </plugin>
      
              </plugins>
      
            </build>
      
          </profile>
      
      

       

      S,

      ALR

        • 1. Re: Maven Failsafe Plugin
          jnorris10
          Andrew, thanks.  Your surefire example suits my needs perfectly.  I never understood why surefire needed to be forked (ie: the failsafe plugin) to accomplish this anyway, and the failsafe name is truly bizarre to me.  I've dropped it now in favor of this.  Thanks.
          • 2. Re: Maven Failsafe Plugin
            alrubinger

            Ah cool.  Yep, it's working for me pretty well too.

             

            If you look at that Sonatype post, I have a comment at the bottom which asks about reliably getting the output JAR (artifact) filename for use in the tests.  Their example has both the artifactId and version hardcoded in.

             

            This is in line with some other discussions we'd been having where we'd like a ShrinkWrap archive to represent the "current" artifact, so we're testing what's built.  The drawback here is that you'd have to run the full build to get the test, as opposed to currently (where the IDE can incrementally compile and then execute if you define what's targeted for the artifact).


            S,

            ALR

            • 3. Re: Maven Failsafe Plugin
              germanescobar

              Just one minor thing I noticed in your solution: your integration tests will be included in unit tests. The problem is that surefire plugin includes the **/*TestCase.java pattern (which includes your **/*IntegrationTestCase.java). So, either you directly exclude that pattern for unit tests or change your pattern for integration tests (i.e. **/*TestIntegration.java).

               

              Now, that makes me think if you can declare two times the surefire plugin, once for unit tests and the other for integration tests. Is that why you use a profile for your integration tests? In that case, the FailSafe Plugin would make sense.

               

              What I think of the FailSafe plugin is that is a shortcut for what you are doing, where you don't need to specify the phase or to include the <includes> tag (as the article says, the FailSafe plugin will look for a different pattern).

              • 4. Re: Maven Failsafe Plugin
                germanescobar

                germanescobar wrote:

                 

                Now, that makes me think if you can declare two times the surefire plugin, once for unit tests and the other for integration tests. Is that why you use a profile for your integration tests? In that case, the FailSafe Plugin would make sense.

                 

                Just realized that you can have multiple executions and configuration is per execution.

                • 5. Re: Maven Failsafe Plugin
                  alrubinger

                  Actually, my pattern for Surefire unit tests is configured to "**/*UnitTestCase.java".

                   

                  Justin Edelson just gave us some more insight; Failsafe Plugin will apparently execute the post-integration-test phase even on test failure, where Surefire will not.  That's an interesting point to consider if the container start/stop/deploy/undeploy is handled by pre-integration or post- phases.  For Arquillian, luckily we have it all running as part of the test itself, so we sidestep these issues and handle shutdown gracefully in a "finally" anyway.

                   

                  S,

                  ALR