简体   繁体   English

如何使用 Cobertura Maven 插件查看 HTML 覆盖率报告?

[英]How to view HTML coverage report using Cobertura Maven plugin?

I want to generate and view a coverage report for a Java-Maven project.我想生成并查看 Java-Maven 项目的覆盖率报告。

I've added the following to pom.xml :我在pom.xml添加了以下内容:

<reporting>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>cobertura-maven-plugin</artifactId>
      <version>2.2</version>
      <configuration>
        <formats>
          <format>html</format>
        </formats>
      </configuration>
    </plugin>
  </plugins>
</reporting>

When I run mvn cobertura:cobertura it builds successfully and reports to the console that Cobertura Report generation was successful but I can't find the report.当我运行mvn cobertura:cobertura它会成功构建并向控制台Cobertura Report generation was successful但我找不到报告。

If I cd into target/cobertura I find a file called cobertura.ser but I have no idea what to do with it.如果我cdtarget/cobertura我会找到一个名为cobertura.ser的文件,但我不知道如何处理它。

Edit: After re-examining the docs, thanks to Andreas_D, I've added the <reporting> tag, but get the same result.编辑:重新检查文档后,多亏了 Andreas_D,我添加了<reporting>标签,但得到了相同的结果。

This in the Build section:这在构建部分:

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

And then this in the Reporting section:然后在报告部分:

<reporting>
    ...
    <plugins>
        ... 
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <check></check>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
        </plugin>
        ...
    </plugins>
    ...
</reporting>

Execute mvn cobertura:cobertura执行mvn cobertura:cobertura

Then look for index.html inside the target/site/cobertura/ folder.然后在target/site/cobertura/文件夹中查找index.html

Have a look at the plugin's documentation, there's an example .看看插件的文档, 有一个例子 Pretty sure that you have to add a <reporting> element to actually produce the report.非常确定您必须添加<reporting>元素才能实际生成报告。

I just tried here in my project, you can do the following also:我刚刚在我的项目中尝试过,您也可以执行以下操作:

a) run mvn cobertura:cobertura a) 运行 mvn cobertura:cobertura
b) it should generate a folder called 'site' b)它应该生成一个名为“站点”的文件夹
c) you can open the index.html (inside site/sobertura folder) in whatever browser and inspect the results of coverage. c) 您可以在任何浏览器中打开 index.html(在 site/sobertura 文件夹内)并检查覆盖结果。

If nothing works - Try this http://technikes.com/how-to-generate-code-coverage-report-in-java-jacoco-graphical-report/ you can get code coverage report in html and xml format如果没有任何效果 - 试试这个http://technikes.com/how-to-generate-code-coverage-report-in-java-jacoco-graphical-report/你可以获得 html 和 xml 格式的代码覆盖率报告

This is amazing as I publish my report in html and xml这太棒了,因为我用 html 和 xml 发布了我的报告

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

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