From a37c6a4a3de119d472df32bb4c776c0da0af68fe Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Wed, 18 Jan 2023 15:33:12 +0200 Subject: [PATCH] PR#143 Fix tests can't run on API 21 Seems like jacoco androidTestCoverage breaks tests on API 21 with Resource.NotFound for some reason. It works well on newer API levels. To workaround it, we simply disable that coverage for CI. --- .github/workflows/pull-request-jobs.yml | 2 +- README.md | 3 ++- gradlescripts/jacoco.config.gradle | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-request-jobs.yml b/.github/workflows/pull-request-jobs.yml index 920f129..240c695 100644 --- a/.github/workflows/pull-request-jobs.yml +++ b/.github/workflows/pull-request-jobs.yml @@ -122,7 +122,7 @@ jobs: force-avd-creation: false emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: true - script: ./gradlew connectedDebugAndroidTest + script: ./gradlew connectedDebugAndroidTest -PdisableAndroidTestCoverage=true - name: Upload Test Results uses: actions/upload-artifact@v2 if: always() diff --git a/README.md b/README.md index a432d78..3155dff 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,8 @@ To see an aggregated code coverage report: - task `runTestAndJacocoRootReport` will run all the sub modules reports and tests then run `jacocoRootReport`. ### Issues -*One issue, is that the androidTest reports don't work with the sharedTest module setup, this issue is reported [here](https://issuetracker.google.com/issues/250130118)* +- One issue, is that the androidTest reports don't work with the sharedTest module setup, this issue is reported [here](https://issuetracker.google.com/issues/250130118) +- Another issue, is that seems like the tests fail with Resource.NotFound on API 21 if `enableAndroidTestCoverage` is true, so I disabled that for CI. By shared test module setup I mean a module like `app-shared-test`, which has a dependency graph of: - app-shared-test -> app.main diff --git a/gradlescripts/jacoco.config.gradle b/gradlescripts/jacoco.config.gradle index d6cd8a6..bfd9978 100644 --- a/gradlescripts/jacoco.config.gradle +++ b/gradlescripts/jacoco.config.gradle @@ -64,8 +64,10 @@ def setupAndroidJacoco(Project module, ArrayList fileFilter, String jaco jacoco.includeNoLocationClasses = true jacoco.excludes = fileFilter } - android.buildTypes.debug.enableAndroidTestCoverage true - android.buildTypes.debug.enableUnitTestCoverage true + // on API 21 enableAndroidTestCoverage makes the tests crash with resource not found issue + def disableAndroidTestCoverage = findProperty("disableAndroidTestCoverage") ?: false + android.buildTypes.debug.enableAndroidTestCoverage = !disableAndroidTestCoverage + android.buildTypes.debug.enableUnitTestCoverage = true jacoco.toolVersion = "$jacocoVersion"