-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Measure code coverage #836
Comments
@julianharty Would you be interested to measure this within the automated tests? |
In the past we have looked into this a bit. We have a build variant with a coverage library I think for instrumentation tests and unit test coverage can be measured by Android Studio. I think we would need to flesh these out more to meet the requirements of this issue though. |
Hi @mhutti1 @kelson42 If I understood the requirements of the issue correctly, we need a way to measure the code coverage of the project. Most other open source Android projects use https://codecov.io/. It can easily be integrated with Travis. Sample integration example: https://github.com/codecov/example-android It will display the code coverage for each PR. Let me know if you want to integrate this. |
@srv-twry Welcome back! |
@abdulwd Hi, I wasn't aware of this. I thought we run integration tests on Travis only. I'll do some more research to see if I can find a solution to this. |
@srv-twry Welcome back, I have enhanced the requirements. All-in-one they are quite standards. |
The priority of this ticket has been raised up, we need to get these number for october. If someone wants to volunteering on this, I would be really thankful. Maybe @siddharth2010 this is finally a solution to measure all the good work you have done on testing :) |
A quick update. I have been able to generate a plausible code coverage when running the tests on a particular device (a Nexus 5x running Android 8.0.0). When I ran the tests on a Samsung Phone (a Galaxy2 SM-G360F running Android 5.0.2) the coverage report was generated but showed 0 lines were covered i.e. coverage of 0.0% I'd temporarily changed the debug build flavor to enable test coverage as I was struggling to get any coverage report to be generated; (this may be caused by other factors Action: now I've got something working I'll reverse this change and retest) Several tests failed on the Samsung device. I don't yet know if failing tests are enough to cause the 0 lines covered on this device. Action: I'll investigate or whether the cause is a function of running code coverage on [some] Samsung devices generating a coverage file of 0 bytes e.g. see https://stackoverflow.com/a/37475182/340175 It's also not clear yet which build targets actually cause the tests to run and the coverage report to be generated. There are numerous build targets that include coverage:
The first one that worked for me is: Note: this is with
|
Reverting the testCoverageEnabled to false in I've experimented by changing the section called |
Seems like the Samsung device is falling foul of the 0 length coverage file reported by others:
|
Yet more notes, if only for my own failing memory... Here are the details for the report's index.html (last updated over an hour ago, when all the tests passed for the coverage build target)
However the coverage data is more recent:
This behaviour is unwelcome and the effect is the coverage report is misleading. Running |
Here, finally seems to be the way to circumvent various gotchas related to generating code coverage for the tests, at least on devices that provide coverage reports with data in. This answer is 3 years old https://groups.google.com/forum/#!topic/adt-dev/DUGRuTm6u1g
which was the key to enabling me to use a buildType other than Note: I've tested (using Gradle 4.6, 2 Android devices, and various build targets from both the command line using the gradle wrapper and also Android Studio 3.2 Preview) that I can:
Limitations: |
Wow, this 1 line change was painful to discover and apply. Many of the details are in #836 NB: We've still to arrange and enable code coverage to be generated in the CI process.
Wow, this 1 line change was painful to discover and apply. Many of the details are in #836 NB: We've still to arrange and enable code coverage to be generated in the CI process.
For those that follow on, here's one of the best examples of the problem and the way we addressed the issue: https://stackoverflow.com/questions/31720389/coverage-on-android-build |
@julianharty We really can't have the testBuildType set to coverage. I spent 3 hours trying to work out why it wasn't working and it was giving me completely unrelated errors. We need to change it back to debug. There's probably a way to pro grammatically change it when needed. |
@macgills Might that be that you have done all the work to achieve this? |
Yes, the pr I just merged addresses this |
Resolved by #1176, closing |
As part of our deal with the Foundation we're supposed to increase code coverage but in order to do so we should have the means to do it.
We need A HTML based report:
The text was updated successfully, but these errors were encountered: