Hello! I'm trying to find the easiest way to gener...
# android
c
Hello! I'm trying to find the easiest way to generate code coverage reports for unitTest and androidTest (Im assuming jacoco will be used, but im not necessarily tied to using jacoco. i just want code coverage reports 😅 ) It seems like jacoco is now built into AGP and so enabling it should be easy, but I'm almost confused if it is actually this easy now or what. the official docs on it are sparse (IMO) I did
enableUnitTestCoverage = true
in build.gradle and now I have an additional task in gradle called
:app:createDebugUnitTestCoverageReport
which generates an html report. this is great. At a baseline... enabling code cov (via jacoco) wasn't hard. Customizing it though does seem hard 1. Calling plugins { jacoco } is not necessary? 2. How can I remove classes/packages from being included in the coverage report? 3. I can enable
enableAndroidTestCoverage = true
but I dont get any gradle task generated to create those reports
This seems to work now. idky
t
eyes on this one because I'll be interested to learn how others do it. My current work projects use both the AGP flags at different times as well as some custom report tasks with some custom config so that my coverage report will span multiple sub projects. androidTest coverage is a pain, the
enableAndroidTestCoverage
afaik just turns on a bytecode transform to instrument it for measurement, but its all on you to pull the .exec files from the device that ran the test and create the reporting task. (pretty sure the instrumentation is just sampling periodically because the coverage reports don't seem to be deterministic) My gradle coverage tasks don't merge unit/ui though since they run in different jobs. I maintain a self hosted version of codecov which lets you upload from multiple jobs before it reports back to a PR.
c
ugh. that indeed sounds like a world of pain. every project ive been on has like 500 lines of code in gradle just to setup code coverage metrics. i thought maybe we've evolved past that.
☝️ 2
p
This is one of the spaces in Android that has a lot of room for improvement. You may try Kover, I can't tell bc I haven't tried it yet but is the Kotlin legitimate alternative, apparently
c
save us @Xavier Ducrohet lol
😆 2
x
We're actively working on this because it's very lacking right now. Can you file a bug about (2), and provide more details on what you need? This was not part of our reqs.
❤️ 2
c
Thanks xav, created this: https://issuetracker.google.com/issues/462394156 If anyone else wants to upvote or, hell create your own jacoco/code coverage wish list issue and paste here and we can all upvote. code coverage seems soooo basic. and im tired of having (what feels like) super hacky setups in everrrrrry project im in.
⬆️ 1