Skip to content

Commit

Permalink
fix(build): assert that more than zero androidTests executed
Browse files Browse the repository at this point in the history
Sometimes an emulator "runs" tests, but it actually discovered zero
tests, runs zero tests, and still reports success. Lookin' at you API21.

Fixes #11078
  • Loading branch information
mikehardy committed Apr 25, 2022
1 parent 099b229 commit 5f22b76
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,24 @@ task installGitHook(type: Copy) {
}
tasks.getByPath(':AnkiDroid:preBuild').dependsOn installGitHook

// Issue 11078 - some emulators run, but run zero tests, and still report success
task assertNonzeroAndroidTests() {
doLast {
File folder = file("./build/outputs/androidTest-results/connected/flavors/play")
File[] listOfFiles = folder.listFiles({d, f-> f ==~ /.*.xml/ } as FilenameFilter)
for (File file : listOfFiles) {
String[] matches = file.readLines().findAll { it.contains('testsuite tests="0"')}
if (matches.length != 0) {
throw new GradleScriptException("androidTest executed 0 tests for " + file.name + " - Probably a bug with the emulator. Try another image.", null)
}

}
}
}
afterEvaluate {
tasks.getByPath(':AnkiDroid:connectedPlayDebugAndroidTest').finalizedBy(assertNonzeroAndroidTests)
}

apply from: "./robolectricDownloader.gradle"
apply from: "./jacoco.gradle"
apply from: "../lint.gradle"
Expand Down

0 comments on commit 5f22b76

Please sign in to comment.