0
votes

I need to generate jacoco report and publish it in sonar for the junit test cases in hybris project. When I publish the jacoco report in sonar, the code coverage includes OOB classes also.

I have excluded the unwanted extensions using sonar.excludedExtensions=xx,yy I need to exclude some directories inside my custom extensions.

I tried using sonar.jacoco.excludes=x.y.z.* and sonar.exclusions=xx/** but nothing works.

How can I exclude classes or directories during jacoco analysis. I have OOB acc-ant-sonar.xml file as below in hybris which drives the jacoco analysis.

<project name="acc.ant.sonar" xmlns:jacoco="antlib:org.jacoco.ant">
    <taskdef uri="antlib:org.jacoco.ant" resource="path/antlib.xml">
        <classpath path="xx.jar"/>
    </taskdef>

    <target name="jacocoalltests" description="runs allstests with jacoco attached">

        <jacoco:agent property="agentvmparam"
                      append="true"
                      output="file"
                      destfile="output_path/jacoco.exec"
                />

        <property name="testclasses.extensions" value="${extname}"/>
        <ant dir="${platformhome}" target="alltests" inheritrefs="false">
            <property name="standalone.javaoptions" value="${agentvmparam} ${standalone.javaoptions}"/>
        </ant>
    </target>
  </project>
1

1 Answers

1
votes

you have multiple possibilities, which you can use together, or alone

  1. telling sonar to ignore oob-classes by setting sonar.coverage.exclusions- as described here https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

  2. configuring jacoco to only track your classes with ìncludes https://www.eclemma.org/jacoco/trunk/doc/ant.html - but i highly recommend to look at the documentation, we just use that for the javaagent directly, and i am not 100% sure if this is 100% working the same way.

    includes=your.package.*
    
  3. might be useful take a look at the Hybris test target -> you can configure packages with testclasses.packages, to reduce the tests which are running. This also might kill your oob coverage, as those test for oob code will not be executed