From 5eb8bbc5507800c2e59d047a425c1e31150ddcad Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Tue, 6 Sep 2022 12:05:56 +0300 Subject: [PATCH 1/2] 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 | 4 ++-- sample/build.gradle | 4 ++-- utils/build.gradle | 4 ++-- wrapper/build.gradle | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01744eff..212d1bf1 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..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 From b0e8aefc8b84b02d3a794818a74672729a212e28 Mon Sep 17 00:00:00 2001 From: Ephraim Kigamba Date: Wed, 7 Sep 2022 14:16:29 +0300 Subject: [PATCH 2/2] Change API level to 24 - Fix flaky build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 212d1bf1..34a4dd16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: - name: Run Instrumented Tests manually uses: reactivecircus/android-emulator-runner@v2 with: - api-level: 22 + api-level: 24 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