The code coverage from RobolectricTestRunner unit test code is not honored.
TonyTangAndroid opened this issue · 8 comments
First of all, thank you for making the effort writing this gradle library to generate the code coverage. After exploring an ocean of blogs, github sample, code snippet, etc for the past three days, I finally come across this repository, the best one and the most potential one that is to rule the world of unified code coverage report. All of other repositories carry all kind of issues, such as out-of-date gradle config, verbose configuration for every module, etc. Only this one gets things done at the most sensible way. So thank you, again. I would never imagine that it has been so challenging to get multiple code coverage report generated.
I have been conducting test with this library. Other than the known issues that you mentioned in the README, I am reporting a new issue. It seems that the code coverage from RobolectricTestRunner unit test code is not honored. You could reproduce this issue from this code sample project. Basically, I just copied the code from your multi-module
and added an unit test run by RobolectricTestRunner
. From the Android Studio Code Coverage report, it says the code is unit test coveraged. But the generated one from rootCodeCoverageReport
says the otherwise.
Would you please confirm this issue ?
@TonyTangAndroid thanks for your detailed bug report! I can confirm that there is an issue with unit-test coverage in some cases, I'm not quite sure what the cases exactly are.
I was already investigating this issue for a while, as you can see here:
Today after looking at your report I did some more digging and found the potential cause, I will write some code, tests and release something for you to try as soon as posible.
Awesome. I will keep an eye on it and will verify when it is ready. Take your time.
I seem to have found something to fix this issue, however in your case you need some additional configuration to make code coverage work correctly in combination with Robolectric unit tests:
app/build.gradle:
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
android {
// ...
}
includeNoLocationClasses = true
makes sure Jacoco adds instrumentation to classes for which you do not have the sources (Robolectric).
Screenshot that shows working coverage:
This fix will be included in release 1.2.1, which is soon going to be released.
Release 1.2.1 is now available.
Hi Rolf, I confirm that with your extra setup, it will include the RobolectricTestRunner
unit test coverage. Just for clarification, bumping up to 1.2.1
does not solve it the issue automatically, I still need to manually include this extra setup script. Is this intended?
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
android {
// ...
}
For the actual details, please refer to this pull request TonyTangAndroid/NeoTechCodeCoverageSample#3
Hi @TonyTangAndroid,
For now this is intentional, but in future updates I will be adding a special setting for this, so it becomes easier to configure.
Awesome. Thank you for the clarification. This is by far the best coverage tools that I have ever come across the whole Internet. Combining the codecov support, it is unbelievable easy to get it set-up, which used to be unbelievably challenging to set it up properly prior this repo. Appreciate for this excellent work.