JaCoCo coverage report setups(exclude test classes)

lucian.marcuta

Im generating a jacoco coverage report using the following target :

   <target name="report" depends="test">

            <!-- This task needs the collected execution data and ... -->
            <executiondata>
                <file file="${result.exec.file}" />
            </executiondata>

            <!-- the class files and optional source files ... -->
            <structure name="JaCoCo Ant Example">
                <classfiles>
                    <fileset dir="${result.classes.dir}" />
                </classfiles>
                <sourcefiles encoding="UTF-8">
                    <fileset dir="${src.dir}" >
                    <exclude name="**/*Test*.class"/>
                    </fileset>  
                </sourcefiles>
            </structure>

            <!-- to produce reports in different formats. -->
            <html destdir="${result.report.dir}" />
            <csv destfile="${result.report.dir}/report.csv" />
            <xml destfile="${result.report.dir}/report.xml" />
        </jacoco:report>
    </target>

The problem is that the report takes into account the code from unit tests and I consider this fact a mistake. This way, your line coverage percent and instruction coverage will be artificially increased(because test lines are considered 100% covered) and report correctness is pretty affected. I tried to add this tag

<exclude name="**/*Test*.class"/

under fileset tag, hoping that testClasses will be excluded, but it doesnt works. Do you have any ideas for my problem? I want to avoid programmatically report modification. Thanks!

Lydia Ralph

You need to exclude the Test class files from the classfiles fileset:

<structure name="JaCoCo Ant Example">
        <classfiles>
            <fileset dir="${result.classes.dir}">
                <exclude name="**/*Test*.class"/>
            </fileset>
        </classfiles>
        <sourcefiles encoding="UTF-8">
            <fileset dir="${src.dir}" />
        </sourcefiles>
</structure>

See documentation:

"Note that the classfiles and sourcefiles elements accept any Ant resource collection. Therefore also filtering the class file set is possible and allows to narrow the scope of the report, for example:

<classfiles>
    <fileset dir="classes">
        <include name="org/jacoco/examples/important/**/*.class"/>
    </fileset>
</classfiles> 

This is because the actual report is done from the classfiles. The sourcefiles are there to include highlighted source code in the report - as of course the human eye can't read compiled code.

Again from the documentation:

classfiles: Container element for Ant resources and resource collections that can specify Java class files, archive files (jar, war, ear etc. or Pack200) or folders containing class files. Archives and folders are searched recursively for class files.

sourcefiles: Optional container element for Ant resources and resource collections that specify corresponding source files. If source files are specified, some report formats include highlighted source code. Source files can be specified as individual files or as source directories.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JaCoCo coverage report setups(exclude test classes)

From Dev

JaCoCo Debug Coverage Test Report

From Dev

Jacoco Test coverage report shows 0%

From Dev

Jacoco Test coverage report shows 0%

From Dev

Jacoco generate coverage report for only a single test class

From Dev

SonarQube: including a subset of test coverage classes in report

From Dev

Exclude folder in jacoco coverage report

From Dev

Jacoco Coverage and Report Task with Ant

From Dev

Jacoco coverage of unit test code

From Dev

jacoco coverage per test setup

From Dev

maven jacoco: not generating code coverage report

From Dev

maven jacoco plugin does not generate coverage report

From Dev

Display test coverage using jacoco in gradle

From Dev

Generate test coverage with Jacoco and Circle CI fails

From Dev

Gradle jacoco coverage report with more than one submodule(s)?

From Dev

Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

From Dev

generating jacoco code coverage report for all sub modules

From Dev

Gradle jacoco coverage report with more than one submodule(s)?

From Dev

SonarQube coverage missing some lines covered by Jacoco report

From Dev

Clover XML Report - Classes and Trait coverage formula

From Dev

Excluding Lombok classes from Sonar coverage report

From Dev

Gradle Jacoco - coverage reports includes classes excluded in configuration

From Dev

JUnit report to show test functionality, not coverage

From Dev

How to generate test coverage report in Meteor / Velocity?

From Dev

Android test coverage report for multi module app

From Dev

How to add static member variables Jacoco Test Coverage?

From Java

Maven Jacoco Configuration - Exclude classes/packages from report not working

From Dev

Jacoco coverage for switch statement

From Dev

Jacoco - Zero Percent Coverage

Related Related

  1. 1

    JaCoCo coverage report setups(exclude test classes)

  2. 2

    JaCoCo Debug Coverage Test Report

  3. 3

    Jacoco Test coverage report shows 0%

  4. 4

    Jacoco Test coverage report shows 0%

  5. 5

    Jacoco generate coverage report for only a single test class

  6. 6

    SonarQube: including a subset of test coverage classes in report

  7. 7

    Exclude folder in jacoco coverage report

  8. 8

    Jacoco Coverage and Report Task with Ant

  9. 9

    Jacoco coverage of unit test code

  10. 10

    jacoco coverage per test setup

  11. 11

    maven jacoco: not generating code coverage report

  12. 12

    maven jacoco plugin does not generate coverage report

  13. 13

    Display test coverage using jacoco in gradle

  14. 14

    Generate test coverage with Jacoco and Circle CI fails

  15. 15

    Gradle jacoco coverage report with more than one submodule(s)?

  16. 16

    Code Coverage Report with Jacoco for IntegrationTests runs on Weblogic server

  17. 17

    generating jacoco code coverage report for all sub modules

  18. 18

    Gradle jacoco coverage report with more than one submodule(s)?

  19. 19

    SonarQube coverage missing some lines covered by Jacoco report

  20. 20

    Clover XML Report - Classes and Trait coverage formula

  21. 21

    Excluding Lombok classes from Sonar coverage report

  22. 22

    Gradle Jacoco - coverage reports includes classes excluded in configuration

  23. 23

    JUnit report to show test functionality, not coverage

  24. 24

    How to generate test coverage report in Meteor / Velocity?

  25. 25

    Android test coverage report for multi module app

  26. 26

    How to add static member variables Jacoco Test Coverage?

  27. 27

    Maven Jacoco Configuration - Exclude classes/packages from report not working

  28. 28

    Jacoco coverage for switch statement

  29. 29

    Jacoco - Zero Percent Coverage

HotTag

Archive