From 7dead408c341d3b4e53f2a2a6b9015ae42b6fe45 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 | 6 ++++++ README.md | 1 + library/build.gradle | 4 ++-- sample/build.gradle | 4 ++-- utils/build.gradle | 4 ++-- wrapper/build.gradle | 4 ++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01744eff..c09fdcb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,15 +32,21 @@ jobs: run: git fetch origin master && git rev-list --first-parent --count origin/master - name: Download Robolectric deps run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh + - 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: Clean project 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..7f6dca38 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -64,7 +64,7 @@ android { debug { // See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183 - testCoverageEnabled false + testCoverageEnabled true if (project.rootProject.file("local.properties").exists()) { Properties properties = new Properties() @@ -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..1182c243 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -41,7 +41,7 @@ android { debug { // See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183 - testCoverageEnabled false + testCoverageEnabled true buildConfigField "String", "MAPBOX_SDK_ACCESS_TOKEN", localProperties["mapbox.sdk.token"] buildConfigField "String", "CGR_USERNAME", localProperties["cgr.username"] buildConfigField "String", "CGR_PASSWORD", localProperties["cgr.password"] @@ -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..cc03ba76 100644 --- a/utils/build.gradle +++ b/utils/build.gradle @@ -37,7 +37,7 @@ android { debug { // See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183 - testCoverageEnabled false + testCoverageEnabled true } } @@ -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..5a2e8e45 100644 --- a/wrapper/build.gradle +++ b/wrapper/build.gradle @@ -33,7 +33,7 @@ android { debug { // See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183 - testCoverageEnabled false + testCoverageEnabled true } } @@ -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