-
Notifications
You must be signed in to change notification settings - Fork 24
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
Code Coverage not reported for instrumented tests (Android library module) on AGP 7.0 #36
Comments
I'm not exactly sure what causes this, but I suspect it has something to do with using:
It could be that the plugin gets configured before you configure the new srcDirs, meaning that the plugin will not see these? You could try to move the plugin apply block to after this block. But this is just me guessing. Can you share this project with me so I can do some testing? |
Hi thanks for helping! you can check the project here: https://github.com/raquezha/heograpiya |
I've tried applying the apply block after |
Hi @raquezha took me a while to take a look at this, but I found a few things: Looking at the report that is generated, it is missing all execution data, which is needed to calculate coverage. You can check this for your self by going to the sessions part of the report: This can have multiple causes, but in this case this happens because the Android Gradle Plugin updated where these files are located since version 7.0. This means the Plugin needs a small update. However I also spotted this, which will also prevent coverage (even if I update the plugin):
|
Thank you! looking forward for the fix, If you need someone to test, I'll gladly help! |
Update: However, on your specific project, there is still coverage missing. So I'm investigating what exactly causes that. |
Update 2: Kotlin 1.5 is the issue? Did some more testing and I found that even though there is a small change in AGP 7.0 (they moved the location of the I found that the generated When I downgrade Kotlin to version 1.4.x everything works as expected, the ` In other words, it seems this is not specifically a AGP 7.0 issue, but more likely a JaCoCo or Kotlin issue. On the other hand AGP 7.0 itself depends on Kotlin 1.4, so maybe that is what's causing the issue? I also tried upgrading to Gradle 7.1, JaCoCo 8.8 (snapshot), Kotlin 1.5.10. But that didn't work. For now I only know that downgrading to Kotlin 1.4, seems to work (as a workaround). Coverage in Android Studio Now the reason you are seeing coverage in Android Studio is because you are probably running the Intellij code coverage runner, and not the Jacoco coverage runner. If you switch to Jacoco you will notice that Android Studio will not report any coverage. I will try to search further but as of now I don't have any idea's left. Maybe I should file a bug? But where? JaCoCo? Kotlin? |
hi, is there any progress on the kotlin 1.5 coverage issue? if help is needed let me know. |
@kherink I could use some help here in finding out which tool actually causes the missing coverage. I'm currently working on a bare-minimal example that reproduces this (without my Plugin being involved), it's work in progress but at least I'm able to reproduce it*. *Although it is already reproducible by running code coverage via Android Studio (IntelliJ) using JaCoCo, thus skipping this plugin, the Gradle JaCoCo plugin and Android Gradle plugin. |
@Rolf-Smit I will have a look and let you know what I find. |
@Rolf-Smit hi, you can reproduce it by this example. |
@Rolf-Smit i'll look at it this weekend |
Hi I don't use this plugin.. But I came across this issue when finding the same problem with code coverage with my own custom script after upgrading to AGP 7+ and Kotlin 1.5+.
Coverage now seems to now work for me (at least my test reports now show hits), by omitting this line. Not sure what has changed in AGP, and if this effects anything else, but I thought i'd share here anyway, just it case it helps someone, or helps progress the investigation further. |
This library needs |
Thanks for taking the time to add this comment here! I also noticed this but figured it was a bug, since you would expect that when this property is true it would actually instrument the classes, omitting it would make me think it would not instrument the classes. Anyhow, this library indeed uses the testCoverageEnabled property to see which modules to include in the combined coverage report. If removing this property works I can rework the library to no longer use that property, possibly introducing a different method to tell the plugin which modules to use for the combined report. |
Hi @Rolf-Smit Does the |
It's worth noting, that this bug has been raised here https://issuetracker.google.com/issues/195860510 |
@AshMosahebTAB thanks for sharing that here. I'm at this point 100% sure that this is not something I can fix, but this is something that needs fixing on the Android (Google) side of things. |
@anticafe
This library does not introduce In the README you can find information on how to configure this library in such a way that it either executes instrumented tests (test that run on an Android device) or pure Java unit tests (tests that run on your machine): https://github.com/NeoTech-Software/Android-Root-Coverage-Plugin#3-configuration |
Update: It seems Google finally stepped in and fixed the issue in AGP version 7.2.0: https://issuetracker.google.com/issues/195860510#comment12 Unfortunately the fix will not be released this month, they expect to release a beta version of AGP 7.2.0 that includes this fix around December 13th. |
In Android Gradle Plugin 7.0 a bug was introduced causing instrumented coverage for Android library projects to fail (https://issuetracker.google.com/issues/195860510). This bug has been fixed in AGP 7.2.0-alpha06. This contains the necessary changes to make this plugin work with AGP 7.2 and some general dependency upgrades: - Increased the target and compile SDK version to API level 31 for the test fixtures. This also requires the build to use Java 11. - Upgraded several test related dependencies (AppCompat, Google Truth, Robolectric etc.). - Upgraded to Kotlin 1.5 Fixes: #36
A SNAPSHOT release is now available that supports Android Gradle Plugin version Since this SNAPSHOT is only available in Maven Central (Gradle Plugin Portal does not support SNAPSHOT releases), you cannot use this release using the normal
Once there is a stable 7.2. release I will release a stable 1.5 release (or when Google decides to fix this on top of 7.0.4 or 7.1-beta I will create a special release for those). |
@Rolf-Smit
At these locations only versions up to 1.4.0 are available (at least publicly visible). |
You indeed need to use a special repository, the snapshot repository from Maven Central:
You must add this reposiotry to your plugin repository section. settings.gradle (top of the file):
|
Edit: I might have been stupid and never published a special Gradle Plugin Marker artifact to maven central, without a Marker artifact Gradle cannot map the plugin ID to a maven module. For SNAPSHOTS this is now fixed (I just published a new one), so you no longer need this to use SNAPSHOTS:
|
Google finally released a stable version of the Android Gradle Plugin 7.2 that fixes #36, this means we can finally create a new stable release for this plugin: - Most of the plugin has been rewritten to only make use of public Android Gradle Plugin API's, functionally this should not change anything compared to previous releases. - Adds a minimum required Android Gradle Plugin version check, using an Android Gradle Plugin version that is too old will result in a Gradle build error. - No longer logs warning messages for (sub)projects (modules) that do not use the Android Gradle Plugin. Instead this is now an info message. This info message will only show for (sub)projects that have a build.gradle file (see #45). - No longer logs warning messages asking to apply the JaCoCo plugin yourself, instead the plugin takes care of this now. - Potentially fixes #42, since JaCoCo will now always be applied by the plugin at the root project.
Hi I'm trying this on my test multi-module project before trying this on the other project I'm working on. I've followed the steps and run
./gradlew rootCoveragePlugin
but got this report:--
com.raquezha.heograpiya.splash is 0% but when I run it in Android Studio local coverage it recognize the tests:
--
here's the file structure
as you can see Android Studio recognizes the local code coverage of splash module and says its 100% lines covered
here's my top-level build.gradle
here's the splash module build.gradle:
I'm using:
I'm using canary because this is only a test project I want to test new stuff
The text was updated successfully, but these errors were encountered: