Maven Cobertura: unit test failed but succeeded

I configured cobertura code coverage in my pom:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <configuration> <instrumentation> <excludes> <exclude>**/*Exception.class</exclude> </excludes> </instrumentation> <formats> <format>xml</format> <format>html</format> </formats> </configuration> </plugin> 

And start the test by running the following command:

 mvn clean cobertura:cobertura 

But if one of the unit test crashes, Cobertura only logs this information and does not put a build error.

 Tests run: 287, Failures: 1, Errors: 1, Skipped: 0 Flushing results... Flushing results done Cobertura: Loaded information on 139 classes. Cobertura: Saved information on 139 classes. [ERROR] There are test failures. ................................. [INFO] BUILD SUCCESS 

How to configure Cobertura build error failed in one of unit test fail?

Thanks in advance.

+4
source share
2 answers

If you use a special target from the cobertura plugin, you cannot make maven fail to build if the test was not successful. The goal of the plugin will be successful.

You can bind the cobrarur run to the life cycle phase (for example, a test). This will cause the cobertura target to run with this phase ( mvn clean test ) and fail if this phase fails.

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <configuration> <formats> <format>xml</format> <format>html</format> </formats> </configuration> <executions> <execution> <phase>test</phase> <goals> <goal>cobertura</goal> </goals> </execution> </executions> </plugin> 

The disadvantage of this solution is that the goal of the cobrabert will be executed through each phase of test .

+3
source

You can set the haltOnFailure property to true.

 <configuration> ... <check> ... <haltOnFailure>true</haltOnFailure> ... </check> </configuration> 
0
source

Source: https://habr.com/ru/post/1341645/


All Articles