Combining code coverage reports from FTL and unit tests

Following up on my previous post https://medium.com/mobile-testing/generating-code-coverage-from-espresso-tests-running-in-firebase-test-lab-e98edcea7bdf where we saw about generating code coverage numbers for espresso tests running in FTL, this post looks at how to combine them.

This is not a new idea, I am borrowing a lot from https://medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa but customizing it our CI/CD pipeline.

Assuming that your coverage.ec file is already created on gcloud you need to find a way fetch it down. gsutil is the most straightforward way. So I have something like this

mkdir -p app/build/test-results/Debug
mkdir -p app/build/test-results/jacoco

gsutil -m cp -r gs://${BUCKET_NAME}/**.xml app/build/test-results/Debug
gsutil -m cp -r gs://${BUCKET_NAME}/**/artifacts/coverage.ec app/build/test-results/jacoco

Note: bucket name has to be unique and should be identifiable for our setup we just reuse the job name.

As a final step we have a createReports task which has jacocoPublishser like this

step([$class          : 'JacocoPublisher',
exclusionPattern: '**/R.class, **/R$*.class, **/BuildConfig.*, **/Manifest*.*, **/FakeDataLoader.*, **/Migration.*',
execPattern : "**/testEspressoEnvDebugUnitTest.exec, **/coverage.ec",
classPattern : "${jenkinsBuild}/build/intermediates/classes/debug/com/godaddy/gdm/telephony",
sourcePattern : '**/src/main/java'
)]

The most important thing here is that excePattern is able to merge the coverage.ec file created from FTL into your jacoco report.

Like what you read? Give Satyajit Malugu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.