Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force maven to execute next goals after tests failures

I'm running tests on a project using the surefire plugin and then need to generate a report using the "site" goal, even if there are failed tests.

The thing is that by default surefire forces the build to fail in a case of failed tests and no further goals are executed. So that I set the following configuration to surefire:

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

This works well and the "site" goal is always executed, but in such a case the status of the build is always "Success" so that I can't set up emails notification.

Is there a proper way to execute the next goals after a "test" goal without ignoring the failures in the surefire plugin?

like image 916
BohdanN Avatar asked Sep 05 '17 10:09

BohdanN


1 Answers

You could use:

  • -DskipTests=true to skip test execution entirely
  • -Dmaven.test.failure.ignore=true to ignore test failures
  • --fail-at-end to let the build continue after the test phase and only fail (if there are test failures) when the entire build cycle is complete

Given this statement ...

This works well and the "site" goal is always executed, but in such a case the status of the build is always "Success" so that I can't set up emails notification.

... I think you want to use --fail-at-end. According to the docs its behaviour is:

--fail-at-end - if a particular module build fails, continue the rest of the reactor and report all failed modules at the end instead

like image 130
glytching Avatar answered Oct 11 '22 15:10

glytching