Gradle Android - Test Coverage by Legacy Test Project Framework
I am migrating a rather large and complex old project to Gradle. I have many library projects where each project has its own test sub-projects. The project structure looks like this:
- LibraryX
-- LibraryXTestsOne
-- LibraryXTestsTwo
- LibraryY
-- LibraryYTests
....
Each library is configured as follows:
- The main source contains all the library code
- The androidTest source set is empty.
Each test project is set up like this:
- It displays the parent library as a dependency
- Main source is empty
- The androidTest source kit contains all the test codes
With this configuration, I manage to run the test with: libraryTestsA: connectedAndroidTest, but I can't get the test coverage to work. I turn it on through
buildTypes{
debug{ testCoverageEnabled true }
}
Apparently the parent library classes are not instrumental, so the code coverage is zero.
Any suggestions?
It turns out you just need to set testCoverageEnabled
in true
for all projects / libraries the test project depends on. This will be enough to measure your code.
You still need to create a custom jacocoReport task, though, since the one provided by the Android plugin looks at classes and sources in the project's main source set, which are empty in a configuration like mine.