Skip to content

Commit

Permalink
test: copy testlib common files into androidTest directly
Browse files Browse the repository at this point in the history
we are unable to depend on them in androidTestImplementation terms
because android gradle plugin has a bug that breaks coverage with
a shared test/androidTest dep

we want the code to be truly shared though and just need to work around
the issue temporarily (we hope)

so a build-time copy seems the least-worst alternative
  • Loading branch information
mikehardy committed Jun 24, 2024
1 parent fde043f commit f766d11
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 12 additions & 1 deletion AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ tasks.register('installGitHook', Copy) {
// to run manually: `./gradlew installGitHook`
tasks.named('preBuild').configure { dependsOn('installGitHook') }

tasks.register('copyTestLibIntoAndroidTest', Copy) {
into new File(rootProject.rootDir, 'AnkiDroid/src/androidTest/java/com/ichi2/testutils')
from new File(rootProject.rootDir, 'testlib/src/main/java/com/ichi2/testutils')
into ('common') {
from 'common'
}
}
tasks.named('preBuild').configure { dependsOn('copyTestLibIntoAndroidTest') }

// Issue 11078 - some emulators run, but run zero tests, and still report success
tasks.register('assertNonzeroAndroidTests') {
doLast {
Expand Down Expand Up @@ -408,7 +417,9 @@ dependencies {
// for testing flows
testImplementation libs.cashapp.turbine

androidTestImplementation project(':testlib')
// we should depend directly on the common testlib for androidTest, but we cannot
// until coverage-breaking issue is fixed https://issuetracker.google.com/issues/332746900
// androidTestImplementation project(':testlib')

// May need a resolution strategy for support libs to our versions
androidTestImplementation libs.androidx.espresso.core
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The files in this directory are copied from testlib dynamically during build
# Copy used instead of `androidTestImplementation(':testlib')` until android gradle plugin
# issue that breaks coverage for shared test/androidTest deps is fixed
# see https://issuetracker.google.com/issues/332746900#comment2
*.kt
18 changes: 18 additions & 0 deletions test-android-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Fixup build / test errors as needed
#git cherry-pick 8a1c48d0ab2978d76e53774ff9b4e0ea2986cdfb --allow-empty --no-commit --no-gpg-sign

# Run the test
./gradlew jacocoAndroidTestReport

# Was there coverage?
cat AnkiDroid/build/reports/jacoco/jacocoAndroidTestReport/jacocoAndroidTestReport.xml |grep 'covered="0"/></report>' > /dev/null
if [ $? == 0 ]; then
echo no coverage detected
exit 1
else
echo there appears to be coverage
fi

exit 0

0 comments on commit f766d11

Please sign in to comment.