From 8aaf0419f9e0e2a877a09e3021d96ad5aa6df500 Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Mon, 24 Apr 2017 17:19:52 -0700 Subject: Run Robolectric tests on build server Configure the build server task to run 'test' task, and zip the result XMLs to host-test-reports for tradefed to pick it up. Test: out/dist/host-test-reports get generated by TreeHugger Bug: 37677781 Change-Id: I6162ce0996912b7445ef92c44e48625c4fb4e48f --- library/self.gradle | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'library/self.gradle') diff --git a/library/self.gradle b/library/self.gradle index fe68744..b7cbd55 100644 --- a/library/self.gradle +++ b/library/self.gradle @@ -62,12 +62,36 @@ android.lintOptions { android.libraryVariants.all { variant -> variant.assemble.dependsOn(tasks.findByName('lint')) } -// Output all test APKs to the distribution folder def distTask = tasks.findByName('dist') if (distTask) { + // Output all test APKs to the distribution folder android.testVariants.all { variant -> // Make the dist task depend on the test variant, so the test APK will be built distTask.dependsOn variant.assemble // TODO: remap the different test variants to different file names } + + // Output the Robolectric test results to host-test-reports/*.zip + afterEvaluate { + android.unitTestVariants.all { variant -> + def task = tasks.findByName('test' + variant.name.capitalize()) + gradle.taskGraph.whenReady { taskGraph -> + task.ignoreFailures = taskGraph.hasTask(distTask) + } + + // Create a zip file of the XML test reports and dist it to host-test-reports. + // The file path and format should match GradleHostBasedTest class in TradeFed. + def junitReport = task.reports.junitXml + if (junitReport.enabled) { + def zipTask = project.tasks.create("zipResultsOf${task.name.capitalize()}", Zip) { + from junitReport.destination + archiveName = task.name + 'Result.zip' + destinationDir = junitReport.destination.parentFile + } + tasks.dist.dependsOn zipTask + zipTask.mustRunAfter task + dist.file zipTask.archivePath.path, "host-test-reports/${zipTask.archiveName}" + } + } + } } -- cgit v1.2.3