How does Cobertura work with JUnit?

ⅰ亾dé卋堺 提交于 2019-12-04 02:27:25

Cobertura uses ASM which is a general purpose bytecode manipulation and analysis framework. On every line of java code there are 3 lines added to the existing classes to count things for the report it produces. When Cobertura is included in your classpath and configured correctly and you execute your unit tests, it will produce a datafile called cobertura.ser which is used to produce an xml or html report.

Basic usage: with Maven: http://www.mojohaus.org/cobertura-maven-plugin/usage.html

neethi

Cobertura monitors tests by instrumenting the bytecode with extra statements to log which lines are and are not being reached as the test suite executes.

Cobertura calculates coverage both by the number of lines tested and by the number of branches tested. For a first pass, the difference between these two is not hugely important. Cobertura also calculates the average McCabe's cyclomatic complexity for the class.

If using maven this can be configured in POM:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <formats>
                <format>html</format>
                <format>xml</format>
            </formats>
        </configuration>
    </plugin>

If using ANT it can be configured with the taskdef statement in the build.xml file:

   <taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>

Reference for ant-cobertura integration can be found at https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!