| import com.android.tools.internal.testing.DevicePool; |
| |
| apply plugin: 'java' |
| apply plugin: 'kotlin' |
| apply plugin: 'jacoco-tools-base' |
| |
| repositories { |
| maven { url = uri(rootProject.cloneArtifacts.repository) } |
| } |
| |
| dependencies { |
| testCompile project(':base:build-system:integration-test:framework') |
| testCompile project(':analytics-library:protos') |
| testCompile project(':apksig') |
| testCompile project(':base:builder') |
| testCompile project(':base:builder-model') |
| testCompile project(':base:gradle') |
| testCompile project(':base:instant-run:instant-run-client') |
| testCompile project(':base:sdk-common') |
| testCompile project(':base:testing-infrastructure:device-pool:device-provider') |
| testCompile project(':base:testutils') |
| testCompile project(':base:java-lib-model') |
| |
| testCompile libs.kotlin_stdlib |
| testCompile libs.kotlin_test |
| |
| testCompile gradleApi() |
| testCompile libs.apache_commons_io |
| testCompile libs.apache_commons_lang |
| testCompile libs.google_api_client |
| testCompile libs.google_storage_client |
| testCompile libs.groovy |
| testCompile libs.junit |
| testCompile libs.protobuf |
| testCompile libs.protobuf_util |
| testCompile libs.truth |
| |
| testCompile libs.mockito_core |
| |
| // Add dependency on plugin code. Exclude transitive dependencies to avoid conflict due to |
| // Groovy versions. |
| testCompile(project(':base:gradle-core')) { |
| transitive = false |
| } |
| testCompile(project(':base:gradle')) { |
| transitive = false |
| } |
| } |
| |
| configurations { |
| // google-api-client depends on guava-jdk5. |
| testCompile.exclude group: 'com.google.guava', module: 'guava-jdk5' |
| } |
| |
| def testEnvironment = |
| /* |
| * We keep the following properties: |
| * - starting with CUSTOM_ e.g. CUSTOM_ANDROID_HOME |
| * - DEBUG_INNER_TEST: to allow us to debug tests |
| * - starting with LC_ or LANG_, so the locale is set up correctly |
| * - BUILDBOT_: to get BuildBot specific information e.g. buildId used for performance tests |
| */ |
| System.getenv().findAll { entry -> |
| String key = entry.key |
| key.startsWith("CUSTOM_") || |
| key.startsWith("ACTD_") || // environment variables for uploading to Dana |
| key.startsWith("PERF_") || // environment variables for controlling perf tests |
| key == "USE_GRADLE_NIGHTLY" || |
| key == "BENCHMARK_EXPERIMENT" || |
| key == "DEBUG_INNER_TEST" || |
| // For NDK tests on Windows. See init.mk. |
| key == "OS" || |
| key == "PROCESSOR_ARCHITECTURE" || |
| key == "ProgramW6432" || |
| key == "ProgramFiles(x86)" || |
| key == "TMP" || |
| key == "TEMP" || |
| // For AccentCharacterAndProguardTest |
| key.startsWith("LC_") || |
| key.startsWith("LANG") || |
| key.startsWith("BUILDBOT_") || |
| // For local benchmarking |
| key == "LOCAL_BENCHMARK_LOCATION" || |
| key == "LOCAL_PROTO_BENCHMARK_LOCATION" |
| } |
| |
| testEnvironment << [ |
| TEST_TMPDIR: |
| System.env.TEST_TMPDIR != null |
| ? new File(System.env.TEST_TMPDIR) |
| : project.buildDir, // Use the same environment variable as Bazel for now. |
| CUSTOM_REPO: new File(rootProject.ext.androidHostOut, "repo").toString() |
| + File.pathSeparator |
| + rootProject.file("../prebuilts/tools/common/m2/repository/").toString(), |
| CUSTOM_IMPROVED_DEPENDENCY_RESOLUTION : "true" |
| ] |
| |
| // These tasks will not depend on publishLocal, so they will run integration |
| // tests against whatever version of the plugin is in ../../../out/repo. This |
| // allows us to run integration tests with different versions of Java, without |
| // rebuilding the plugin. |
| task testPrebuilts(type: Test) |
| task connectedIntegrationTestPrebuilts(type: Test) |
| task connectedIntegrationTestPrebuiltsQuarantine(type: Test) |
| |
| File tempFile = new File(project.buildDir, 'tmp') |
| tempFile.mkdirs() |
| |
| configure([test, testPrebuilts]) { |
| description = |
| "Runs the project integration tests. This requires an SDK either from the Android " + |
| "source tree, under out/..., or an env var ANDROID_HOME." |
| systemProperties['jar.path'] = jar.archivePath |
| systemProperties['java.io.tmpdir'] = tempFile.absolutePath |
| environment = testEnvironment |
| |
| // Always run the task, when requested. |
| outputs.upToDateWhen { false } |
| |
| maxParallelForks = Runtime.runtime.availableProcessors() / 4 |
| |
| useJUnit { |
| if (System.properties['test.includeCategories'] != null) { |
| def categories = System.properties['test.includeCategories'].split(',') |
| String defaultPackage = "com.android.build.gradle.integration.common.category." |
| categories = categories.collect { it.charAt(0).isUpperCase() ? defaultPackage + it : it } |
| includeCategories categories as String[] |
| } |
| excludeCategories "com.android.build.gradle.integration.common.category.DeviceTests" |
| excludeCategories "com.android.build.gradle.integration.common.category.OnlineTests" |
| excludeCategories "com.android.build.gradle.integration.common.category.DeviceTestsQuarantine" |
| } |
| |
| exclude "com/android/build/gradle/integration/performance/**" |
| exclude "com/android/build/gradle/integration/automatic/**" |
| exclude "**/BazelIntegrationTestsSuite*" |
| } |
| |
| task automaticTest(type: Test) { |
| include "com/android/build/gradle/integration/automatic/**" |
| |
| // Always run the task, when requested. |
| outputs.upToDateWhen { false } |
| environment = testEnvironment |
| } |
| |
| task onlineTest(type: Test) { |
| // Always run the task, when requested. |
| outputs.upToDateWhen { false } |
| environment = testEnvironment |
| |
| useJUnit { |
| includeCategories "com.android.build.gradle.integration.common.category.OnlineTests" |
| } |
| } |
| |
| check.dependsOn automaticTest |
| |
| task connectedIntegrationTest(type: Test) |
| task connectedIntegrationTestQuarantine(type: Test) |
| |
| def allConnectedTestTasks = [ |
| connectedIntegrationTest, |
| connectedIntegrationTestPrebuilts, |
| connectedIntegrationTestQuarantine, |
| connectedIntegrationTestPrebuiltsQuarantine |
| ] |
| |
| |
| configure(allConnectedTestTasks) { |
| testClassesDirs = sourceSets.test.output.classesDirs |
| classpath = sourceSets.test.runtimeClasspath |
| |
| description = |
| "Runs the project integration tests with device tests. This requires an SDK either " + |
| "from the Android source tree, under out/..., or an env var ANDROID_HOME " + |
| "and a device." |
| group = "verification" |
| systemProperties['jar.path'] = jar.archivePath |
| systemProperties['java.io.tmpdir'] = tempFile.absolutePath |
| |
| environment testEnvironment |
| |
| // Always run the task, when requested. |
| outputs.upToDateWhen { false } |
| |
| def count = Math.ceil(Runtime.runtime.availableProcessors() / 4) |
| if (count > 8) { |
| count = 8 |
| } |
| maxParallelForks = count |
| |
| exclude "com/android/build/gradle/integration/performance/**" |
| exclude "com/android/build/gradle/integration/automatic/**" |
| } |
| |
| configure([connectedIntegrationTest, connectedIntegrationTestPrebuilts]) { |
| useJUnit { |
| includeCategories "com.android.build.gradle.integration.common.category.DeviceTests" |
| excludeCategories "com.android.build.gradle.integration.common.category.DeviceTestsQuarantine" |
| } |
| } |
| |
| configure([connectedIntegrationTestQuarantine, connectedIntegrationTestPrebuiltsQuarantine]) { |
| useJUnit { |
| includeCategories "com.android.build.gradle.integration.common.category.DeviceTestsQuarantine" |
| } |
| } |
| |
| |
| task performanceTest(type: Test) { |
| include "com/android/build/gradle/integration/performance/**" |
| |
| testClassesDirs = sourceSets.test.output.classesDirs |
| classpath = sourceSets.test.runtimeClasspath |
| |
| description = |
| "Runs the project performance tests. This requires an SDK either " + |
| "from the Android source tree, under out/..., or an env var ANDROID_HOME." |
| group = "verification" |
| systemProperties['jar.path'] = jar.archivePath |
| environment = testEnvironment |
| |
| reports { |
| junitXml.destination project.file("${project.buildDir}/perf-results") |
| } |
| outputs.upToDateWhen { false } |
| |
| } |
| |
| configure([test, testPrebuilts, onlineTest, connectedIntegrationTest, |
| connectedIntegrationTestPrebuilts, performanceTest]) { |
| testLogging { |
| events = ['FAILED', 'SKIPPED', 'STANDARD_ERROR'] |
| displayGranularity = 2 // Show test class and method. |
| exceptionFormat = 'full' |
| showCauses = true |
| } |
| } |
| |
| task buildTestDependencies { |
| dependsOn ':base:instant-run:instant-run-server:jar' |
| } |
| |
| DevicePool devicePool = new DevicePool(); |
| |
| task('startDevicePool').doLast { |
| // This port number needs to be kept in sync with DevicePoolClient. |
| devicePool.start(3431) |
| } |
| |
| task('stopDevicePool').doLast { |
| devicePool.stop() |
| } |
| |
| startDevicePool.finalizedBy stopDevicePool |
| allConnectedTestTasks.forEach({task -> stopDevicePool.mustRunAfter(task)}) |
| |
| automaticTest.dependsOn ':publishLocal' |
| onlineTest.dependsOn ':publishLocal' |
| test.dependsOn buildTestDependencies, ':publishAndroidGradleLocal' |
| testPrebuilts.dependsOn buildTestDependencies |
| allConnectedTestTasks.forEach({task -> task.dependsOn buildTestDependencies, startDevicePool}) |
| connectedIntegrationTest.dependsOn ':publishLocal' |
| connectedIntegrationTestQuarantine.dependsOn ':publishLocal' |
| performanceTest.dependsOn ':publishLocal' |
| |
| |
| if (tasks.findByName("jacocoTestReport") != null) { |
| jacocoTestReport { |
| sourceSets project(':base:gradle').sourceSets.main |
| sourceSets project(':base:gradle-core').sourceSets.main |
| sourceSets project(':base:builder').sourceSets.main |
| sourceSets project(':base:builder-model').sourceSets.main |
| sourceSets project(':base:builder-test-api').sourceSets.main |
| } |
| |
| // Due to memory constraints, apply jacoco only when jacocoTestReport is invoked. Make sure to |
| // rerun tests when generating report jacoco. |
| gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph -> |
| if (taskGraph.hasTask(jacocoTestReport)) { |
| test.environment("ATTACH_JACOCO_AGENT", "yes") |
| } |
| } |
| } |