0

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.

john
  • 11,311
  • 40
  • 131
  • 251
  • There is a command line utility with Cobertura that you can use to provide an explicit subdirectory of classes, or I believe you can list the classes individually. – Kon Jun 08 '14 at 20:48
  • @Kon I see. If there is anything I can add explicitly in my eclipse with the list of test classes that I want to instrument then that will help me a lot. – john Jun 08 '14 at 20:52
  • No idea, never used the Eclipse plugin. When I used Cobertura, there was no Eclipse plugin that supported JDK 7. I used the standalone tools. Look into those. – Kon Jun 08 '14 at 21:01

1 Answers1

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

cbr
  • 12,563
  • 3
  • 38
  • 63
metacubed
  • 7,031
  • 6
  • 36
  • 65
  • Thanks metacubed for the help. Suppose I have three java test files which I don't want to measure using cobertura. All my java test file is in `/src/test/java` and I don't want to instrument these three java test files test1.java, test2.java and test3.java. – john Jun 08 '14 at 23:10
  • ... So in exclude, it should be like this - `/sampleproject/src/test/java/com/example/project/main/test/Test1.class /sampleproject/src/test/java/com/example/project/main/test/Test2.class /sampleproject/src/test/java/com/example/project/main/test/Test3.class` Right? And does these tests will be run or not? – john Jun 08 '14 at 23:11
  • @user2809564 You have to exclude the `.class` files found in `sampleproject/target/...` which are produced after compilation. And yes, the tests will still run. – metacubed Jun 08 '14 at 23:13
  • I see.. Is there any to avoid even running those tests? – john Jun 09 '14 at 00:08
  • @user2809564 Extended edits and new questions in comments are strongly discouraged as per the [guidelines](http://meta.stackexchange.com/questions/156900/whats-the-policy-on-follow-up-questions). Please look for existing questions or post a new one - it should be answered fairly quickly by the community. Also, please remember to close/accept this question if you think it solves the original problem. Thanks! – metacubed Jun 09 '14 at 15:14