I am using OpenClover in an Azure DevOps Pipeline.
The problem: Whereas the coverage given in target/site/clover/index.html
, when I run clover locally, is (sadly) around 45%, in Azure DevOps it is at 71%.
The reason for that is that the coverage report in AzDO, which is based on target/site/clover.xml
, also includes test code, which in general has a coverage of 100%, thusly skewing the result.
How can I rid the coverage report of including test code? What I have tried to no avail is using classfilters
in ReportGenerator - which is responsible for converting clover.xml to Cobertura so that AzDO can interpret it. Neither of the following worked:
classfilters: '-*Test.java'
classfilters: '-*Test'
classfilters: '-*Test.class'
For context, here is my pipeline.
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx1024m'
mavenAuthenticateFeed: true
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
jdkArchitectureOption: 'x64'
publishJUnitResults: false
goals: 'clean clover:setup test clover:aggregate clover:clover'
- task: reportgenerator@4
inputs:
reports: '$(Build.SourcesDirectory)/target/site/clover/clover.xml'
classfilters: '-*Test'
targetdir: '$(Build.SourcesDirectory)/CoverageResults'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CoverageResults/Cobertura.xml'
And this is the part of the pom file relating to clover:
<build>
<plugins>
<plugin>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>4.4.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
From ReportGenerator 4.6.4, test projects can be excluded without the (fragile) file filter.