How to run cobertura code coverage for few test classes not all of my test classes?

烂漫一生 提交于 2019-12-13 21:15:38

问题


I am using Cobertura in eclipse to generate the code coverage for my java maven project and it works fine. I have around 15 tests classes. Whenever I am running maven build, it generates code coverage for all those 15 classes.

Is there any way, I can run cobertura code coverage report for few of my test classess instead of all the test classes? I also have AllTests in which I have mentioned only few of my test classes but I guess cobertura doesn't use AllTests.


回答1:


If you are using the Maven Cobertura plugin, you can specify filtering using two separate tags:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>${cobertura.version}</version>
    <configuration>
        <instrumentation>
            <ignores>
                <ignore>org.apache.log4j.*</ignore>
                ...
            </ignores>
            <excludes>
                <exclude>**/package1/package2/**/*.class</exclude>
                ...
            </excludes>
        </instrumentation>
    </configuration>
</plugin>

<ignores> tells Cobertura to exclude all calls to the specified package/class. The example above will ignore all lines that are log4j logging calls.

<excludes> tells Cobertura to not instrument certain files. Hits to those classes are not recorded during the test run. Here ** indicates recursive search (any directory at any depth below current). So the example states: Exclude any classes that have the package1.package2 package anywhere in their fully qualified name.

You also have an <includes> to specify a white-list of classes instead of <excludes>.

Other details can found here: Mojo's Maven plugin for Cobertura - Usage



来源:https://stackoverflow.com/questions/24110634/how-to-run-cobertura-code-coverage-for-few-test-classes-not-all-of-my-test-class

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