Build: Make robolectric tests run offline without downloading artifacts
#KTI-1367
This commit is contained in:
committed by
Space Team
parent
bb8d3a0f80
commit
009cda0c60
@@ -7,6 +7,8 @@ plugins {
|
||||
}
|
||||
|
||||
val robolectricClasspath by configurations.creating
|
||||
val robolectricDependency by configurations.creating
|
||||
|
||||
val androidExtensionsRuntimeForTests by configurations.creating
|
||||
val layoutLib by configurations.creating
|
||||
val layoutLibApi by configurations.creating
|
||||
@@ -37,8 +39,9 @@ dependencies {
|
||||
testApi(project(":kotlin-test:kotlin-test-jvm"))
|
||||
testApi(commonDependency("junit:junit"))
|
||||
|
||||
robolectricDependency("org.robolectric:android-all:5.0.2_r3-robolectric-r0")
|
||||
|
||||
robolectricClasspath(commonDependency("org.robolectric", "robolectric"))
|
||||
robolectricClasspath("org.robolectric:android-all:4.4_r1-robolectric-1")
|
||||
robolectricClasspath(project(":kotlin-android-extensions-runtime")) { isTransitive = false }
|
||||
|
||||
embedded(project(":kotlin-android-extensions-runtime")) { isTransitive = false }
|
||||
@@ -65,10 +68,19 @@ javadocJar()
|
||||
|
||||
testsJar()
|
||||
|
||||
val robolectricDependencyDir = "$buildDir/robolectricDependencies"
|
||||
val prepareRobolectricDependencies by tasks.registering(Copy::class) {
|
||||
from(robolectricDependency)
|
||||
into(robolectricDependencyDir)
|
||||
}
|
||||
|
||||
projectTest {
|
||||
dependsOn(androidExtensionsRuntimeForTests)
|
||||
dependsOn(robolectricClasspath)
|
||||
|
||||
dependsOn(prepareRobolectricDependencies)
|
||||
dependsOn(":dist")
|
||||
|
||||
workingDir = rootDir
|
||||
useAndroidJar()
|
||||
|
||||
@@ -86,6 +98,10 @@ projectTest {
|
||||
doFirst {
|
||||
systemProperty("androidExtensionsRuntime.classpath", androidExtensionsRuntimeProvider.get())
|
||||
systemProperty("robolectric.classpath", robolectricClasspathProvider.get())
|
||||
|
||||
systemProperty("robolectric.offline", "true")
|
||||
systemProperty("robolectric.dependency.dir", robolectricDependencyDir)
|
||||
|
||||
systemProperty("layoutLib.path", layoutLibConf.singleFile.canonicalPath)
|
||||
systemProperty("layoutLibApi.path", layoutLibApiConf.singleFile.canonicalPath)
|
||||
}
|
||||
|
||||
+8
-1
@@ -144,13 +144,20 @@ abstract class AbstractParcelBoxTest : CodegenTestCase() {
|
||||
classFileFactory.getClassFiles().forEach { writeClass(it.relativePath, it.asByteArray()) }
|
||||
javaClassesOutputDirectory?.listFiles()?.forEach { writeClass(it.name, it.readBytes()) }
|
||||
|
||||
val robolectricProperties = System.getProperties().propertyNames().asSequence()
|
||||
.map { it.toString() }.filter { it.startsWith("robolectric") }
|
||||
.map { "-D$it=${System.getProperty(it)}" }
|
||||
.toList()
|
||||
.toTypedArray()
|
||||
|
||||
val process = ProcessBuilder(
|
||||
javaExe.absolutePath,
|
||||
"-ea",
|
||||
"-classpath",
|
||||
(libraryClasspath + dirForTestClasses).joinToString(File.pathSeparator),
|
||||
*robolectricProperties,
|
||||
JUnitCore::class.java.name,
|
||||
JUNIT_GENERATED_TEST_CLASS_FQNAME
|
||||
JUNIT_GENERATED_TEST_CLASS_FQNAME,
|
||||
).start()
|
||||
|
||||
val out = process.inputStream.bufferedReader().lineSequence().joinToString("\n")
|
||||
|
||||
Reference in New Issue
Block a user