From 3f45be05717f0200267a3c6799afa9934b0a8ea6 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 6 Sep 2022 12:05:56 +0300 Subject: [PATCH] Add instrumentation tests workaround - Enable testCoverage only for instrumentation tests and disable the flag after - Add the path for the new instrumentation test coverage ec file Relates to #358 --- .github/workflows/ci.yml | 4 ++++ README.md | 1 + library/build.gradle | 2 +- sample/build.gradle | 2 +- utils/build.gradle | 2 +- wrapper/build.gradle | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01744eff..051c8120 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,11 +36,15 @@ jobs: run: ./gradlew clean --stacktrace - name: Build project skipping tests run: ./gradlew build -x test --stacktrace + - name: Enable test coverage for all modules for instrumentation tests + run: sed -i 's/testCoverageEnabled false/testCoverageEnabled true/g' library/build.gradle && sed -i 's/testCoverageEnabled false/testCoverageEnabled true/g' utils/build.gradle && sed -i 's/testCoverageEnabled false/testCoverageEnabled true/g' sample/build.gradle && sed -i 's/testCoverageEnabled false/testCoverageEnabled true/g' wrapper/build.gradle - name: Run Instrumented Tests manually uses: reactivecircus/android-emulator-runner@v2 with: api-level: 22 script: ./gradlew connectedDebug --stacktrace + - name: Disable test coverage for all modules + run: sed -i 's/testCoverageEnabled true/testCoverageEnabled false/g' library/build.gradle && sed -i 's/testCoverageEnabled true/testCoverageEnabled false/g' utils/build.gradle && sed -i 's/testCoverageEnabled true/testCoverageEnabled false/g' sample/build.gradle && sed -i 's/testCoverageEnabled true/testCoverageEnabled false/g' wrapper/build.gradle - name: Run jacocoTestReport for each module run: ./gradlew jacocoTestReport --stacktrace --info - name: Merge jacoco reports from all modules diff --git a/README.md b/README.md index c63881c8..129c3a18 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ This is encountered when Robolectric has problems downloading the jars it needs ``` ./download-robolectric-deps.sh +``` ## License diff --git a/library/build.gradle b/library/build.gradle index 34f31ee3..ba00fa9a 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -200,7 +200,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) { // sourceDirectories.setFrom([mainSrc]) classDirectories.setFrom(files([debugTree])) executionData.setFrom(fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' + 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec', 'outputs/code_coverage/**/connected/**/*coverage.ec' ])) } diff --git a/sample/build.gradle b/sample/build.gradle index 30573d48..8f398b4f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -163,6 +163,6 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) { // sourceDirectories.setFrom(files([mainSrc])) classDirectories.setFrom(files([debugTree])) executionData.setFrom(fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' + 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec', 'outputs/code_coverage/**/connected/**/*coverage.ec' ])) } diff --git a/utils/build.gradle b/utils/build.gradle index 2dce714d..c19a4249 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -92,7 +92,7 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) { // sourceDirectories.setFrom(files([mainSrc])) classDirectories.setFrom(files([debugTree])) executionData.setFrom(fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' + 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec', 'outputs/code_coverage/**/connected/**/*coverage.ec' ])) } diff --git a/wrapper/build.gradle b/wrapper/build.gradle index 3ca288ac..4b5b697b 100644 --- a/wrapper/build.gradle +++ b/wrapper/build.gradle @@ -82,6 +82,6 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) { // sourceDirectories.setFrom(files([mainSrc])) classDirectories.setFrom(files([debugTree])) executionData.setFrom(fileTree(dir: project.buildDir, includes: [ - 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' + 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec', 'outputs/code_coverage/**/connected/**/*coverage.ec' ])) } \ No newline at end of file