SetupWizardLibrary/tools/gradle/dist-unit-tests.gradle
Maurice Lam 65ad0d1c78 Support multiple library test APKs
- Extracted the instrumentation test APK generation code to
  dist-library-instrumentation-tests.gradle, which is enhanced to
  support multiple test APKs for different build variants, so that
  the output APK name will not conflict.
- Extracted Robolectric test code to dist-unit-tests.gradle so that
  it can be more easily reused and for better organization.

Test: ./gradlew, build_for_build_server.sh builds expected artifacts
Change-Id: I7a3c4b3b2c3528fda80deb7778a5af5f7703c913
2017-05-04 12:06:00 -07:00

39 lines
1.7 KiB
Groovy

/**
* This script plugin is used to bundle the host test (e.g. Robolectric) results and dist it in
* a location where TradeFed knows how to parse.
*
* - If a non-dist build is run with test, it will run the normal unit tests, failing the build if
* there are test failures.
* - If a dist build is run with test (e.g. ./gradlew dist test), the build will ignore any test
* failures, and will create a zip of the XML test reports for each test run, and copy them to
* dist/host-test-reports for consumption by TradeFed.
*/
apply plugin: 'dist'
// If unit tests are run as part of the build, dist the test XML reports to host-test-reports/*.zip
android.unitTestVariants.all { variant ->
def task = tasks.findByName('test' + variant.name.capitalize())
gradle.taskGraph.whenReady { taskGraph ->
// Ignore the failures, so the build continues even on test errors when the build is
// running with 'dist'. (Usually as part of a build server build)
task.ignoreFailures = taskGraph.hasTask(tasks.dist)
}
def junitReport = task.reports.junitXml
if (junitReport.enabled) {
// Create a zip file of the XML test reports
def zipTask = tasks.create("zipResultsOf${task.name.capitalize()}", Zip) {
from junitReport.destination
archiveName = task.name + 'Result.zip'
destinationDir = junitReport.destination.parentFile
}
zipTask.mustRunAfter task
// Copy the test reports to dist/host-test-reports
// The file path and format should match GradleHostBasedTest class in TradeFed.
tasks.dist.dependsOn zipTask
dist.file zipTask.archivePath.path, "host-test-reports/${zipTask.archiveName}"
}
}