How to run a maven goal when there is tests failures?
Asked Answered
W

6

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.

Wintergreen answered 10/1, 2012 at 12:10 Comment(1)
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.Wintergreen
K
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...

Kimberliekimberlin answered 20/9, 2012 at 20:48 Comment(1)
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.Throw
E
5

Just do mvn clean install -DskipTests

Excise answered 8/8, 2018 at 6:33 Comment(0)
S
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>
...
Sayette answered 10/1, 2012 at 12:18 Comment(0)
G
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>
Gesticulative answered 15/12, 2018 at 9:39 Comment(0)
O
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
Ornament answered 10/1, 2012 at 12:31 Comment(0)
S
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>
Statue answered 30/3, 2023 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.