Skip to content

Conversation

@k4k7us23
Copy link
Contributor

Problem

In our project we are using gradle managed devices to execute ui tests. Ui tests launch configuration is a bit complicated in our use case, so I had to launch ui tests separately from Android-Root-Coverage-Plugin. And then after ui tests have finished it's execution, I am using :rootCoverageReport" The problem here, is that coverage results from ui tests are being ignored by :rootCoverageReport. This happens only with gradle managed devices, if I manually execute ui tests on connected emulator, and than use :rootCoverageReport to create aggregated coverage report, everything works as expected.

I have created new configuration gradle-managed-device-dont-execute-android-tests.yaml for IntegrationTest.kt, that reproduces the issue above.

Solution

This pull request also contains fix of that problem. Here are key components of the fix:

  1. It turned out that subProject.getExecutionDataFileTree always received includeGradleManagedDevicesResults = false, in case of executeAndroidTests is false. Now that is fixed.
  2. I had to switch from project.tasks.findByPath("$path:allDevices${name}AndroidTest") to subProject.tasks.configureEach inside JacocoReport.addSubProjectVariant. project.tasks.findByPath was always returing null, because task$path:allDevices${name}AndroidTest wasn't configured yet at the time project.tasks.findByPath is called.
  3. The fix introduces explicit dependency between ":rootCoverageReport" and "coverageReport" tasks of subprojects. Without this change, gradle build sometimes was failing with error like
Error: gradle Task : "rootCoverageReport" uses the output of task ':nexusoneapi30DebugAndroidTest" without declaring an explicit or implicit dependency.

@Rolf-Smit
Copy link
Contributor

@k4k7us23 thanks for your pull-request, unfortunately I don't have time to look into this right now, I will have a closer look later this week.

@Rolf-Smit Rolf-Smit self-assigned this Aug 5, 2024
@Rolf-Smit
Copy link
Contributor

@k4k7us23 So it took me a while to take a look at this. Thanks for your contribution, in general I think the changes look good.

However I did make some additional changes and removed the direct dependency between the rootCoverageReport task and coverageReport, as this dependency should not be needed. I could not reproduce the error you where getting either. If you still experience this error, please provide me with a reproducible example. The reason a dependency between these should not be needed, is because these tasks don't use each others output, they only use output from test tasks, so dependencies (explicit or implicit) should only be needed on those.

I also made some additional changes to the integration test so that test cases where this plugin should not execute test tasks are a bit more realistic.

@Rolf-Smit Rolf-Smit force-pushed the fix/gradle_managed_devices_manual_execution branch from e2dfe6b to 6709ae7 Compare September 2, 2024 12:09
@codecov
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.88%. Comparing base (01bed93) to head (0adaaed).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../neotech/plugin/rootcoverage/RootCoveragePlugin.kt 69.23% 3 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #104      +/-   ##
============================================
+ Coverage     80.10%   80.88%   +0.78%     
- Complexity       46       47       +1     
============================================
  Files             8        8              
  Lines           196      204       +8     
  Branches         30       30              
============================================
+ Hits            157      165       +8     
  Misses           11       11              
  Partials         28       28              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

pavel.krylov and others added 3 commits September 2, 2024 15:40
…rt tasks

These tasks should not depend on each other as they do not depend on each others output, if some direct dependency is needed, it will be on the test tasks.
@Rolf-Smit Rolf-Smit force-pushed the fix/gradle_managed_devices_manual_execution branch from 6709ae7 to 0adaaed Compare September 2, 2024 13:40
@Rolf-Smit Rolf-Smit merged commit 92e1318 into NeoTech-Software:master Sep 2, 2024
Rolf-Smit added a commit that referenced this pull request Sep 3, 2024
- Fixed: Code coverage data not picked up when using Gradle Managed Devices in combination with flavors (#102)
- Fixed: Code coverage data not picked up when using Gradle Managed Devices in combination with executeAndroidTests=false (#104)
- Based on Android Gradle Plugin 8.6 API
- Compatible with Gradle version 8.7+
@Rolf-Smit Rolf-Smit mentioned this pull request Sep 3, 2024
Rolf-Smit added a commit that referenced this pull request Sep 3, 2024
- Fixed: Code coverage data not picked up when using Gradle Managed Devices in combination with flavors (#102)
- Fixed: Code coverage data not picked up when using Gradle Managed Devices in combination with executeAndroidTests=false (thanks to @k4k7us23) (#104)
- Based on Android Gradle Plugin 8.6 API
- Compatible with Gradle version 8.7+
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.

2 participants