开发者

Maven Cobertura: unit test failed but build success

I've configured cobertura code coverage in my pom:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
    <ins开发者_高级运维trumentation>
        <excludes>
            <exclude>**/*Exception.class</exclude>
        </excludes>
    </instrumentation>
    <formats>
        <format>xml</format>
        <format>html</format>
    </formats>
</configuration>
</plugin>

And start test by following command:

mvn clean cobertura:cobertura

But if one of unit test fail Cobertura only log this information and doesn't mark build fail.

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 marks build failed in one of unit test fail?

Thanks in advance.


If you run a special goal from the cobertura plugin you can not force maven to fail the build if a test was not passed successfully. The plugin goal will succeed.

You can bind the cobertura run to a lifecycle phase (e.g. test). This will make the cobertura goal 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 cobertura goal will run ich each test phase.


You could set haltOnFailure property to true.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜