Pergunta

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.

Foi útil?

Solução

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...

Outras dicas

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>
...

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

Just do mvn clean install -DskipTests

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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top