1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
import com.android.tools.internal.testing.DevicePool;
apply plugin: 'groovy'
apply plugin: 'jacoco'
repositories {
maven { url = uri(rootProject.cloneArtifacts.repository) }
}
dependencies {
compile gradleApi()
compile localGroovy()
testCompile project(':base:builder-model')
testCompile project(':base:builder')
testCompile project(':base:sdk-common')
testCompile project(':base:lint')
testCompile project(':base:instant-run:instant-run-client')
testCompile project(':base:testutils')
testCompile project(':base:testing-infrastructure:device-pool:device-provider')
testCompile "junit:junit:4.12"
testCompile 'commons-io:commons-io:2.4'
testCompile 'org.apache.commons:commons-lang3:3.3.2'
testCompile "com.google.protobuf:protobuf-java:2.5.0"
testCompile 'com.google.truth:truth:0.28'
testCompile "org.mockito:mockito-core:1.9.5"
// Jacoco version should be the version bundled with Gradle. Not the default version used by
// the plugin.
testCompile 'org.jacoco:org.jacoco.agent:0.7.5.201505241946'
// 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
}
testCompile(project(':base:gradle-experimental')) {
transitive = false
}
}
def testEnvironment = System.getenv().findAll {it.value != null}
testEnvironment << [
PROJECT_BUILD_DIR : project.buildDir,
CUSTOM_REPO : rootProject.file("../out/repo"),
INTEGRATION_TEST : "true",
DATA_BINDING_INTERNAL_REPO : rootProject.file("../tools/data-binding/internal-prebuilts"),
DATA_BINDING_REPO : rootProject.file("../tools/data-binding/maven-repo")
]
// 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)
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 }
forkEvery = 1
maxParallelForks = Runtime.runtime.availableProcessors() / 2
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"
}
exclude "com/android/build/gradle/integration/performance/**"
exclude "com/android/build/gradle/integration/automatic/**"
}
task automaticTest(type: Test) {
include "com/android/build/gradle/integration/automatic/**"
systemProperties['junit.parallel.threads'] = Runtime.runtime.availableProcessors() / 2
// 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)
configure([connectedIntegrationTest, connectedIntegrationTestPrebuilts]) {
testClassesDir = sourceSets.test.output.classesDir
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
// Add to, rather than replace the environment, so that TEST_CLASSPATH_DEPENDENCY,
// REMOTE_TEST_PROVIDER, ADDITIONAL_TEST_CUSTOM_REPO and any dependencies of the remote test
// provider are present in the test environment only for these tests.
environment testEnvironment + ["RECORD_SPANS" : "true"]
// Always run the task, when requested.
outputs.upToDateWhen { false }
forkEvery= 1
def count = Runtime.runtime.availableProcessors()
if (count > 8) {
count = 8
}
maxParallelForks = count
useJUnit {
includeCategories "com.android.build.gradle.integration.common.category.DeviceTests"
}
exclude "com/android/build/gradle/integration/performance/**"
exclude "com/android/build/gradle/integration/automatic/**"
}
task performanceTest(type: Test) {
include "com/android/build/gradle/integration/performance/**"
testClassesDir = sourceSets.test.output.classesDir
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.buildDir}/perf-results"
}
}
task buildTestDependencies {
dependsOn ':base:gradle-core:instrumentIncrementalTestPatches',
':base:gradle-core:instrumentIncrementalTestBaseClasses',
':base:instant-run:instant-run-server:jar'
}
DevicePool devicePool = new DevicePool();
task startDevicePool << {
// This port number needs to be kept in sync with DevicePoolClient.
devicePool.start(3431)
}
task stopDevicePool << {
devicePool.stop()
}
startDevicePool.finalizedBy stopDevicePool
stopDevicePool.mustRunAfter connectedIntegrationTestPrebuilts, connectedIntegrationTest
automaticTest.dependsOn ':publishLocal'
onlineTest.dependsOn ':publishLocal'
test.dependsOn buildTestDependencies, ':publishLocal'
testPrebuilts.dependsOn buildTestDependencies
connectedIntegrationTest.dependsOn buildTestDependencies, ':publishLocal', startDevicePool
connectedIntegrationTestPrebuilts.dependsOn buildTestDependencies, startDevicePool
performanceTest.dependsOn ':publishLocal'
jacocoTestReport {
sourceSets project(':base:gradle-experimental').sourceSets.main
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")
}
}
|