Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Filtering the whole directory #366

Closed
maisreymom opened this issue Jul 31, 2020 · 11 comments
Closed

[Feature request] Filtering the whole directory #366

maisreymom opened this issue Jul 31, 2020 · 11 comments

Comments

@maisreymom
Copy link

maisreymom commented Jul 31, 2020

"-filefilters -*Test.java" kind of works but that would be more useful if there is an option to generate the report for everything under src/main only without including anything under src/test.
e.g. If we have utility classes under src/test that doesn't have the name *Test.java or if we have a class in src/main that is *Test.java

Thanks

@danielpalme
Copy link
Owner

danielpalme commented Jul 31, 2020

Have you tried -assemblyfilters?
E.g. -assemblyfilters:-test*

@maisreymom
Copy link
Author

@danielpalme I tried that, and seem like it doesn't work.

@danielpalme
Copy link
Owner

Please have a look at the generated report. You have to identify the namespaces you want to exclude.
Then modify the -assemblyfilters:-test* accordingly

@EugenDueck
Copy link

EugenDueck commented Jul 31, 2020

@danielpalme

It seems for clover, the value in <package name=" maps to assembly. However in Java, the package name of the test class is in general the same as that of the tested class, for reasons of visibility ("package-private"). So you cannot distinguish test code from production code using assemblyfilter.

If you look at a clover.xml file, it will look like this:

<coverage>
  <project name="my-project 1.0" timestamp="1596157313247">
    ... 
  </project>
  <testproject name="my-project 1.0" timestamp="1596157313247">
    ...
  <testproject>
</coverage>

ReportGenerator treats both identically:

var projectElement = new XElement(
    "project",
    new XAttribute("timestamp", timeStamp));

rootElement.Add(projectElement);

var testProjectElement = new XElement(
    "testproject",
    new XAttribute("timestamp", timeStamp));

rootElement.Add(testProjectElement);

Wouldn't clover users in general be happy if you just ignored the <testproject> element altogether? Who needs a coverage report that includes test code - which will in general be 100% or close to 100%, thus skewing the overall coverage result?

@danielpalme
Copy link
Owner

Wouldn't clover users in general be happy if you just ignored the <testproject> element altogether? Who needs a coverage report that includes test code - which will in general be 100% or close to 100%, thus skewing the overall coverage result?

I don't think so. Coverlet did the same and now test assemblies are included in the results. Some users want that as well.

@EugenDueck
Copy link

EugenDueck commented Aug 1, 2020

The test code being part of the report listing all files does not bother me, but the 100% test code coverage skewing a e.g. 50% production code coverage towards 70% or so does. And I'd be surprised if any user wants the coverage % figure to include coverage from test code.

Be that as it may - could we perhaps get a flag to control that, in case you do not want to change the default?

@danielpalme
Copy link
Owner

Release 4.6.3 of ReportGenerator (should be available within a few minutes) add a new flag to control that behavior.

Add settings:excludeTestProjects=true to your command line parameters. And everything in a testproject node will be ignored.

@EugenDueck
Copy link

EugenDueck commented Aug 2, 2020

Thanks!

I'm using this from AzDO. Your version 4.6.3 has been automatically updated, and I tried this, as well as the camel-caps version excludeTestProjects.

- task: reportgenerator@4
  displayName: 'convert clover report -> cobertura'
  inputs:
    reports: '$(Build.SourcesDirectory)/target/site/clover/clover.xml'
    excludetestprojects: true
    targetdir: '$(Build.SourcesDirectory)/CoverageResults'

However, the parameter does not seem to get recognized - and tests in fact did not get excluded:

Starting: convert clover report -> cobertura
==============================================================================
Task         : ReportGenerator
Description  : ReportGenerator converts coverage reports generated by OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
Version      : 4.6.3
Author       : Palmmedia
Help         : [More Information](https://github.com/danielpalme/ReportGenerator)
==============================================================================
/usr/bin/dotnet /home/vsts/work/_tasks/reportgenerator_be803a55-9253-4895-a525-be570d86f161/4.6.3/tools/netcoreapp2.1/ReportGenerator.dll
 -reports:/home/vsts/work/1/s/target/site/clover/clover.xml
 -targetdir:/home/vsts/work/1/s/CoverageResults
 -reporttypes:HtmlInline_AzurePipelines;Cobertura
 -sourcedirs:
 -historydir:
 -plugins:
 -assemblyfilters:+*
 -classfilters:+*
 -filefilters:+*
 -verbosity:Info
 -title: -tag:20200802.1_#448

A quick grep for "filefilters" vs "excludetest" shows the latter is not present in the following files that contain the former. Perhaps one of them needs to be changed to support the new flag.

  • ./src/ReportGenerator.Core/ReportConfiguration.cs
  • ./src/ReportGenerator.Core/ReportConfigurationBuilder.cs
  • ./src/ReportGenerator.Core/Reporting/Builders/MhtmlReportBuilder.cs
  • ./src/ReportGenerator.Core/Reporting/IReportConfiguration.cs
  • ./src/ReportGenerator.Core/Help.cs
  • ./src/ReportGenerator.Core/Properties/Help.Designer.cs
  • ./src/ReportGenerator.MSBuild/ReportGenerator.cs
  • ./src/ReportGenerator.Console/MSBuild/ReportGenerator.cs

But hey, code coverage surged from 66% (using filefilters) to a respectable 83% - so maybe we should just keep it this way ;-)

@danielpalme
Copy link
Owner

You are right, i'll have to update the Azure DevOps extension to support those settings.

@danielpalme
Copy link
Owner

The following should work with version 4.6.4:

- task: reportgenerator@4
  displayName: 'convert clover report -> cobertura'
  inputs:
    reports: '$(Build.SourcesDirectory)/target/site/clover/clover.xml'
    targetdir: '$(Build.SourcesDirectory)/CoverageResults'
    customSettings: 'settings:excludeTestProjects=true'

@EugenDueck
Copy link

This works! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants