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

Jacoco report target filtering. #6736

Merged

Conversation

jtrobec
Copy link
Contributor

@jtrobec jtrobec commented Nov 8, 2018

Adds an argument for the jacoco jvm coverage processor that filters targets included in reports using a list of regular expressions.

Problem

The current implementation of jacoco code coverage will produce a report that includes all targets used in the test run. This includes targets not directly under test, but dependencies of the package actually under test. As a result, there's a lot of undesirable noise in the reports.

Solution

Introduce a parameter to filter the class files supplied to the jacoco cli when the report is produced. The jacoco cli does not provide a native parameter for exclusions, and instead the best we can do is to exclude class files when generating the reports. Classes that aren't passed to the cli during report generation aren't included in the resulting report.

The parameter I've added is a list of regular expressions. When specified, pants will only pass targets that match one of the regexes to the cli during report generation. Any target that doesn't match the pattern will be excluded, and thus not show up in the report.

…argets included in reports using a list of regular expressions.
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@stuhood stuhood requested a review from jsirois November 8, 2018 02:48
Copy link
Sponsor Member

@stuhood stuhood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good! Will merge on green.

@stuhood
Copy link
Sponsor Member

stuhood commented Nov 12, 2018

You hit a flaky test. Going to merge. Thanks!

@stuhood stuhood merged commit b31bef7 into pantsbuild:master Nov 12, 2018
@jtrobec jtrobec deleted the jtrobec/pants/jacoco-report-filtering branch November 16, 2018 16:25
@ggetv
Copy link

ggetv commented May 22, 2020

Can someone give an example of using this new filter option, cannot find it in the documentation for junit test?

I am using pants 1.15.0, tried to set the option in this way: --test-junit-coverage-jacoco-target-filters="[com.foo.bar,com.foo.bar2]", but got this error: Exception message: Unrecognized command line flags on scope 'test.junit': --coverage-jacoco-target-filters

The full command:

./pants test.junit --cache-test-junit-ignore --test-junit-coverage-processor=jacoco --test-junit-coverage --test-junit-output-mode=ALL --no-test-junit-timeouts --test-junit-html-report --test-junit-open --test-junit-coverage-open --test-junit-coverage-jacoco-target-filters="[com.foo.bar,com.foo.bar2]" "src/test/java/foo::"

I checked release history, 1.15.0 is released on 4/15/2019, so this PR should be included already?

Can someone give some idea how to use this new filter option?

@baroquebobcat
Copy link
Contributor

I think it's just --jacoco-target-filters, not --test-junit-coverage...

@ggetv
Copy link

ggetv commented May 28, 2020

@baroquebobcat yes, --jacoco-target-filters works! thanks so much!
@stuhood if this option is not included in the Pants document, can we please add it? thanks in advance.

@stuhood
Copy link
Sponsor Member

stuhood commented May 28, 2020

It should be, under jacoco on this page: https://www.pantsbuild.org/options_reference.html

@ggetv
Copy link

ggetv commented May 28, 2020

@stuhood found it under jacoco section, thanks a lot! I was looking at test.junit section advanced options, since cobertura exclusion was there. Thanks for the info and help!

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

Successfully merging this pull request may close these issues.

4 participants