9

I would like to know if there is a way to execute a goal when there is test failures?

Since maven stops its execution (fail fast mode) after encountering a test failure, is there any options to launch a goal when there is test failures?

Regards.

xavier.seignard
  • 11,254
  • 13
  • 51
  • 75
  • Thanks for your answers, but maybe I did not explained well my need. I still want the build to fail when there is tests failures. But I want to execute a custom goal I developed just between the test failures and the end of the fail fast maven build. Regards. – xavier.seignard Jan 10 '12 at 12:57

6 Answers6

5

I've been searching for a way to do this as well, with not much success.

However, there is the following question which might provide some general hints:

Maven reporting plugins do not execute if a unit test failure occurs

The idea is that you would run mvn install (or whatever) first, and then run:

mvn -Dmaven.test.skip=true your-plugin:your-goal

This will let you run the build again without running tests, preserving the results for your perusal. Of course, this is only useful if your plugin is parsing the test results...

Community
  • 1
  • 1
hairyhenderson
  • 577
  • 1
  • 7
  • 20
  • Better way is to do this on the `surefire-plugin` so test results will be ignored on the normal build and for full builds with tests you can add and use `failsafe:verify` on the mvn call and it gonna fail instead of success if there are testfailures. Thats the common/best-practice way. – LenglBoy Apr 03 '18 at 14:33
4

Just do mvn clean install -DskipTests

ParisaN
  • 1,816
  • 2
  • 23
  • 55
4

Though not recommended, by setting the surefire property testFailureIgnore to true, you can continue maven execution even when there are test failures.

...
<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.11</version>
    ...
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
        ...
    </configuration>
</plugin>
...
Raghuram
  • 51,854
  • 11
  • 110
  • 122
1

I added this plugin in pom.xml and it worked well.

            <plugin>

               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.19.1</version>
               <configuration>
               <testFailureIgnore>true</testFailureIgnore>
            </configuration>

           </plugin>
Sachindra N. Pandey
  • 1,177
  • 17
  • 15
0

After adding this below plugin, I think what we have done here is we have ignored the test cases. I dont think this is the right solution for it, please provide any optimistic solution.

           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.19.1</version>
           <configuration>
           <testFailureIgnore>true</testFailureIgnore>
        </configuration>

       </plugin>
0

If you want to the build to run KNOWING beforehand that there are going to be failures, you can use:

mvn <goal> -Dmaven.test.skip = true
Pete
  • 10,720
  • 25
  • 94
  • 139