1/** 2 * This script plugin is used to bundle the host test (e.g. Robolectric) results and dist it in 3 * a location where TradeFed knows how to parse. 4 * 5 * - If a non-dist build is run with test, it will run the normal unit tests, failing the build if 6 * there are test failures. 7 * - If a dist build is run with test (e.g. ./gradlew dist test), the build will ignore any test 8 * failures, and will create a zip of the XML test reports for each test run, and copy them to 9 * dist/host-test-reports for consumption by TradeFed. 10 */ 11 12apply plugin: 'dist' 13 14// If unit tests are run as part of the build, dist the test XML reports to host-test-reports/*.zip 15android.unitTestVariants.all { variant -> 16 def task = tasks.findByName('test' + variant.name.capitalize()) 17 gradle.taskGraph.whenReady { taskGraph -> 18 // Ignore the failures, so the build continues even on test errors when the build is 19 // running with 'dist'. (Usually as part of a build server build) 20 task.ignoreFailures = taskGraph.hasTask(tasks.dist) 21 } 22 23 def junitReport = task.reports.junitXml 24 if (junitReport.enabled) { 25 // Create a zip file of the XML test reports 26 def zipTask = tasks.create("zipResultsOf${task.name.capitalize()}", Zip) { 27 from junitReport.destination 28 archiveName = task.name + 'Result.zip' 29 destinationDir = junitReport.destination.parentFile 30 } 31 zipTask.mustRunAfter task 32 33 // Copy the test reports to dist/host-test-reports 34 // The file path and format should match GradleHostBasedTest class in TradeFed. 35 tasks.dist.dependsOn zipTask 36 dist.file zipTask.archivePath.path, "host-test-reports/${zipTask.archiveName}" 37 } 38} 39