繁体   English   中英

JaCoCo Maven 插件生成 XML 格式的报告

[英]JaCoCo Maven plugin generate report in XML format

我正在使用 maven-jacoco-plugin 生成测试覆盖率。 使用的版本是 0.8.7。

运行mvn test命令时,它会生成 exec 格式的报告。

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco-maven-plugin.version}</version>
    <configuration>
        <formats>XML</formats>
    </configuration>
    <executions>
        <!-- Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when Maven
            the Surefire plugin is executed. -->
        <execution>
            <id>jacoco-initialize-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
                <goal>report</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/../target/site/jacoco-aggregate</outputDirectory>
                <!--<destFile>${project.build.directory}/../../target/coverage-reports/jacoco-ut.exec</destFile>-->
                <append>true</append>
                <propertyName>jacoco.agent.argLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-initialize-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>${project.build.directory}/../../target/coverage-reports/jacoco-it.exec</destFile>
                <append>true</append>
                <propertyName>jacoco.agent.argLine</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-merge</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>merge</goal>
            </goals>
            <configuration>
                <fileSets>
                    <fileset>
                        <directory>${project.build.directory}/../../target/coverage-reports/</directory>
                        <includes>
                            <include>*.exec</include>
                        </includes>
                    </fileset>
                </fileSets>
                <destFile>${project.build.directory}/../../target/coverage-reports/jacoco.exec</destFile>
            </configuration>
        </execution>
        <!-- Ensures that the code coverage report for integration tests is created after all tests have been
            run. -->
        <execution>
            <id>jacoco-report</id>
            <phase>verify</phase>
            <goals>
                <goal>report-aggregate</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/../target/site/jacoco-aggregate</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

当我尝试在使用 XML 下添加配置标签时,它给出了一个错误

无法解析 mojo org.jacoco:jacoco-maven-plugin:0.8.8:report-aggregate 的配置参数格式:无法将 java.lang.String 类型的值为“XML”的配置条目“格式”分配给类型的属性java.util.List -> [帮助 1]

任何人都可以建议如何继续前进吗?

您必须添加一个格式节点:

<formats>
    <format>XML</format>
</formats>

在 GitHub 上,您可以找到示例。 像这样: https ://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-report-select-formats/pom.xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM