maven 基于 cobertura-maven-plugin 插件提供单元测试报告

1. 引入maven依赖

<build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.7</version>
            </plugin>
        </plugins>
    </build>

2. 执行命令

mvn cobertura:cobertura

3. 查看测试报告

报告路径

target/site/cobertura/index.html

4. 名词解释

Line Coverage

The percent of lines executed by this test run.

Branch Coverage

The percent of branches executed by this test run.

Complexity

Average McCabes cyclomatic code complexity for all methods. This is basically a count of the number of different code paths in a method (incremented by 1 for each if statement, while loop, etc.)

N/A

Line coverage and branch coverage will appear as "Not Applicable" when Cobertura can not find line number information in the .class file. This happens for stub and skeleton classes, interfaces, or when the class was not compiled with "debug=true."

经验分享 程序员 微信小程序 职场和发展