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 5eb8bbc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 5eb8bbc

Please sign in to comment.