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 ankidroid#11078
  • Loading branch information
mikehardy committed Apr 26, 2022
1 parent dd44e73 commit bc86a19
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,28 @@ 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 {
// androidTest currently creates one .xml file per emulator with aggregate results in this dir
File folder = file("./build/outputs/androidTest-results/connected/flavors/play")
File[] listOfFiles = folder.listFiles({ d, f -> f ==~ /.*.xml/ } as FilenameFilter)
for (File file : listOfFiles) {
// The aggregate results file currently contains a line with this pattern holding test count
String[] matches = file.readLines().findAll { it.contains('<testsuite') }
if (matches.length != 1) {
throw new GradleScriptException("Unable to determine count of tests executed for " + file.name + ". Regex pattern out of date?", null)
}
if (!(matches[0] ==~ /.* tests="\d+" .*/) || matches[0].contains('tests="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 bc86a19

Please sign in to comment.