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

Exclude Superclass functions in jacocoTestReport? #1089

Closed
premacck opened this issue Sep 11, 2020 · 2 comments
Closed

Exclude Superclass functions in jacocoTestReport? #1089

premacck opened this issue Sep 11, 2020 · 2 comments
Labels
declined: duplicate ❌ This issue or pull request already exists declined: question ❌

Comments

@premacck
Copy link

Steps to reproduce

  • Create a kotlin class extending LinkedHashMap<String, String> and add some simple operational functions, that are not overridden from superclass
  • Add Unit test class for that with `@RunWith(MockitoJunitRunner::class)
  • Write tests for the functions created above
  • Add that file to Jacoco includes file filter
  • Run ./gradlew jacocoTestReport -x lint ("-x lint" I was using because lint was taking too much time)
  • In the test report, you will see the functions from the Map class, like remove(Object, Object), and getOrDefault(Object, Object)
  • Coverage report for my class here
  • I tried overriding these functions in the created class but that added the coverage to functions with string parameters, like remove(String, String), and getOrDefault(String, String) but not the functions with Object parameters
  • I also tried annotating the overridden functions with @Generated, which removed the function with String parameters, but not the functions with Object parameters
  • I also tried to exclude the LinkedHashMap, HashMap and Map classes from jacocoTestReport by adding **/java/util/*.* and **/java/util/Map.java to the exclude filter in the gradle.
  • I also tried to filter out the files in gradle using .filter({file -> !file.name.contains('HashMap')}) but still no luck

Expected behaviour

I'd like to have only the functions from that class, and exclude any functions from the superclass, the overridden functions with String parameters could be kept, as it is possible to cover them, and the user may override them, but the funcitons with Object parameters should be excluded

Actual behaviour

Getting functions from super class, that are not in (and cannot be reachable in) the sub class in jacocoTestReport, causing left out branches and instructions

Is there any way to exclude the unreachable Object parameter functions?

  • JaCoCo version: 0.8.5
  • Operating system: MacOS Catalina 10.5.6
    Android Studio:
Build #AI-193.6911.18.40.6514223, built on May 20, 2020
Runtime version: 1.8.0_242-release-1644-b3-6222593 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.6
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
  • Tool integration: Gradle
@Godin
Copy link
Member

Godin commented Sep 14, 2020

For src/Example.kt

class Example : LinkedHashMap<String, String>() {
}

After compilation by Kotlin compiler version 1.3.72

kotlin-1.3.72/bin/kotlinc src/Example.kt -d classes

Output of

javap -v -p classes/Example.class

shows that all methods except constructor are marked as ACC_BRIDGE - for example

  public final boolean remove(java.lang.Object, java.lang.Object);
    descriptor: (Ljava/lang/Object;Ljava/lang/Object;)Z
    flags: ACC_PUBLIC, ACC_FINAL, ACC_BRIDGE

Report generated by JaCoCo 0.8.5

java -jar jacoco-0.8.5/lib/jacococli.jar \
    report \
    --classfiles classes \
    --sourcefiles src \
    --html report

contains these methods

0 8 5

However not report generated by JaCoCo 0.8.6-SNAPSHOT

0 8 6-SNAPSHOT

So closing as a duplicate of #1010

@Godin Godin closed this as completed Sep 14, 2020
@Godin Godin added the declined: duplicate ❌ This issue or pull request already exists label Sep 14, 2020
@premacck
Copy link
Author

premacck commented Sep 15, 2020

Thanks for the detailed solution
Upgrading from 0.8.5 to 0.8.6-SNAPSHOT solved this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined: duplicate ❌ This issue or pull request already exists declined: question ❌
Projects
None yet
Development

No branches or pull requests

2 participants