开发者

How to view HTML coverage report using Cobertura Maven plugin?

开发者 https://www.devze.com 2023-03-06 14:41 出处:网络
I want开发者_如何学运维 to generate and view a coverage report for a Java-Maven project. I\'ve added the following to pom.xml:

I want开发者_如何学运维 to generate and view a coverage report for a Java-Maven project.

I've added the following to 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.

If I cd into target/cobertura I find a file called cobertura.ser but I have no idea what to do with it.

Edit: After re-examining the docs, thanks to Andreas_D, I've added the <reporting> tag, but get the same result.


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

Then look for index.html inside the target/site/cobertura/ folder.


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.


I just tried here in my project, you can do the following also:

a) run mvn cobertura:cobertura
b) it should generate a folder called 'site'
c) you can open the index.html (inside site/sobertura folder) in whatever browser and inspect the results of coverage.


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

This is amazing as I publish my report in html and xml

0

精彩评论

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