Skip to content

Commit

Permalink
Add instrumentation tests workaround
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ekigamba committed Sep 6, 2022
1 parent ef13dbe commit 7dead40
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ This is encountered when Robolectric has problems downloading the jars it needs

```
./download-robolectric-deps.sh
```

## License

Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'
]))
}

Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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'
]))
}
4 changes: 2 additions & 2 deletions utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {

debug {
// See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183
testCoverageEnabled false
testCoverageEnabled true
}
}

Expand Down Expand Up @@ -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'
]))
}

Expand Down
4 changes: 2 additions & 2 deletions wrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {

debug {
// See bug https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/issues/183
testCoverageEnabled false
testCoverageEnabled true
}
}

Expand Down Expand Up @@ -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'
]))
}

0 comments on commit 7dead40

Please sign in to comment.