Test: speed up tests by minimizing number of tasks to run

E.g. avoid building release variants for Android
(extremely slow due to proguard minification, optimization)
This commit is contained in:
Alexey Tsvetkov
2018-06-05 19:25:14 +03:00
parent 0383584f33
commit 451c732b8f
3 changed files with 46 additions and 37 deletions
@@ -58,14 +58,14 @@ class BuildCacheRelocationIT : BaseGradleIT() {
lateinit var firstOutputHashes: List<Pair<File, Int>> lateinit var firstOutputHashes: List<Pair<File, Int>>
workingDir = workingDirs[0] workingDir = workingDirs[0]
firstProject.build("build") { firstProject.build(*testCase.taskToExecute) {
assertSuccessful() assertSuccessful()
firstOutputHashes = hashOutputFiles(outputRoots) firstOutputHashes = hashOutputFiles(outputRoots)
cacheableTaskNames.forEach { assertContains("Packing task ':$it") } cacheableTaskNames.forEach { assertContains("Packing task ':$it") }
} }
workingDir = workingDirs[1] workingDir = workingDirs[1]
secondProject.build("build") { secondProject.build(*testCase.taskToExecute) {
assertSuccessful() assertSuccessful()
val secondOutputHashes = hashOutputFiles(outputRoots) val secondOutputHashes = hashOutputFiles(outputRoots)
assertEquals(firstOutputHashes, secondOutputHashes) assertEquals(firstOutputHashes, secondOutputHashes)
@@ -82,7 +82,8 @@ class BuildCacheRelocationIT : BaseGradleIT() {
val cacheableTaskNames: List<String>, val cacheableTaskNames: List<String>,
val projectDirectoryPrefix: String? = null, val projectDirectoryPrefix: String? = null,
val outputRootPaths: List<String> = listOf("build"), val outputRootPaths: List<String> = listOf("build"),
val initProject: Project.() -> Unit = { } val initProject: Project.() -> Unit = { },
val taskToExecute: Array<String>
) { ) {
override fun toString(): String = (projectDirectoryPrefix?.plus("/") ?: "") + projectName override fun toString(): String = (projectDirectoryPrefix?.plus("/") ?: "") + projectName
@@ -99,15 +100,19 @@ class BuildCacheRelocationIT : BaseGradleIT() {
fun testCases(): List<Array<TestCase>> = listOf( fun testCases(): List<Array<TestCase>> = listOf(
TestCase( TestCase(
"simpleProject", "simpleProject",
taskToExecute = arrayOf("classes", "testClasses"),
cacheableTaskNames = listOf("compileKotlin", "compileTestKotlin") cacheableTaskNames = listOf("compileKotlin", "compileTestKotlin")
), ),
TestCase("simple", projectDirectoryPrefix = "kapt2", TestCase("simple",
projectDirectoryPrefix = "kapt2",
taskToExecute = arrayOf("classes", "testClasses"),
cacheableTaskNames = listOf( cacheableTaskNames = listOf(
"kaptKotlin", "kaptGenerateStubsKotlin", "compileKotlin", "compileTestKotlin", "compileJava" "kaptKotlin", "kaptGenerateStubsKotlin", "compileKotlin", "compileTestKotlin", "compileJava"
), ),
initProject = { File(projectDir, "build.gradle").appendText("\nkapt.useBuildCache = true") } initProject = { File(projectDir, "build.gradle").appendText("\nkapt.useBuildCache = true") }
), ),
TestCase("kotlin2JsDceProject", TestCase("kotlin2JsDceProject",
taskToExecute = arrayOf("assemble", "runDceKotlinJs"),
cacheableTaskNames = listOf("mainProject", "libraryProject").map { "$it:compileKotlin2Js" } + cacheableTaskNames = listOf("mainProject", "libraryProject").map { "$it:compileKotlin2Js" } +
"mainProject:runDceKotlinJs", "mainProject:runDceKotlinJs",
initProject = { initProject = {
@@ -121,6 +126,7 @@ class BuildCacheRelocationIT : BaseGradleIT() {
} }
), ),
TestCase("multiplatformProject", TestCase("multiplatformProject",
taskToExecute = arrayOf("classes", "testClasses"),
cacheableTaskNames = listOf( cacheableTaskNames = listOf(
"lib:compileKotlinCommon", "libJvm:compileKotlin", "libJvm:compileTestKotlin", "lib:compileKotlinCommon", "libJvm:compileKotlin", "libJvm:compileTestKotlin",
"libJs:compileKotlin2Js", "libJs:compileTestKotlin2Js" "libJs:compileKotlin2Js", "libJs:compileTestKotlin2Js"
@@ -128,17 +134,20 @@ class BuildCacheRelocationIT : BaseGradleIT() {
outputRootPaths = listOf("lib", "libJvm", "libJs").map { "$it/build" } outputRootPaths = listOf("lib", "libJvm", "libJs").map { "$it/build" }
), ),
TestCase("AndroidProject", TestCase("AndroidProject",
taskToExecute = arrayOf("assembleDebug"),
cacheableTaskNames = listOf("Lib", "Android").flatMap { module -> cacheableTaskNames = listOf("Lib", "Android").flatMap { module ->
listOf("Flavor1", "Flavor2").flatMap { flavor -> listOf("Flavor1", "Flavor2").flatMap { flavor ->
listOf("Debug", "Release").map { buildType -> listOf("Debug").map { buildType ->
"$module:compile$flavor${buildType}Kotlin" "$module:compile$flavor${buildType}Kotlin"
} }
} }
}, },
outputRootPaths = listOf("Lib", "Android", "Test").map { "$it/build" } outputRootPaths = listOf("Lib", "Android", "Test").map { "$it/build" }
), ),
TestCase("android-dagger", projectDirectoryPrefix = "kapt2", TestCase("android-dagger",
cacheableTaskNames = listOf("Debug", "Release").flatMap { buildType -> taskToExecute = arrayOf("assembleDebug"),
projectDirectoryPrefix = "kapt2",
cacheableTaskNames = listOf("Debug").flatMap { buildType ->
listOf("kapt", "kaptGenerateStubs", "compile").map { kotlinTask -> listOf("kapt", "kaptGenerateStubs", "compile").map { kotlinTask ->
"app:$kotlinTask${buildType}Kotlin" "app:$kotlinTask${buildType}Kotlin"
} }
@@ -33,21 +33,21 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("android-butterknife", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("android-butterknife", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("build", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
assertFileExists("app/build/generated/source/kapt/release/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.java") assertFileExists("app/build/generated/source/kapt/debug/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.java")
assertFileExists("app/build/intermediates/classes/release/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.class") assertFileExists("app/build/intermediates/classes/debug/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.class")
assertFileExists("app/build/tmp/kotlin-classes/release/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class") assertFileExists("app/build/tmp/kotlin-classes/debug/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class")
if (isLegacyAndroidGradleVersion(androidGradlePluginVersion)) { if (isLegacyAndroidGradleVersion(androidGradlePluginVersion)) {
// we don't copy classes with new AGP // we don't copy classes with new AGP
assertFileExists("app/build/intermediates/classes/release/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class") assertFileExists("app/build/intermediates/classes/debug/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class")
} }
} }
project.build("build", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertTasksUpToDate(":compileReleaseKotlin", ":compileReleaseJavaWithJavac") assertTasksUpToDate(":compileDebugKotlin", ":compileDebugJavaWithJavac")
} }
} }
@@ -56,16 +56,16 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("android-dagger", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("android-dagger", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("build", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
assertFileExists("app/build/generated/source/kapt/release/com/example/dagger/kotlin/DaggerApplicationComponent.java") assertFileExists("app/build/generated/source/kapt/debug/com/example/dagger/kotlin/DaggerApplicationComponent.java")
assertFileExists("app/build/generated/source/kapt/release/com/example/dagger/kotlin/ui/HomeActivity_MembersInjector.java") assertFileExists("app/build/generated/source/kapt/debug/com/example/dagger/kotlin/ui/HomeActivity_MembersInjector.java")
assertFileExists("app/build/intermediates/classes/release/com/example/dagger/kotlin/DaggerApplicationComponent.class") assertFileExists("app/build/intermediates/classes/debug/com/example/dagger/kotlin/DaggerApplicationComponent.class")
assertFileExists("app/build/tmp/kotlin-classes/release/com/example/dagger/kotlin/AndroidModule.class") assertFileExists("app/build/tmp/kotlin-classes/debug/com/example/dagger/kotlin/AndroidModule.class")
if (isLegacyAndroidGradleVersion(androidGradlePluginVersion)) { if (isLegacyAndroidGradleVersion(androidGradlePluginVersion)) {
// we don't copy classes with new AGP // we don't copy classes with new AGP
assertFileExists("app/build/intermediates/classes/release/com/example/dagger/kotlin/AndroidModule.class") assertFileExists("app/build/intermediates/classes/debug/com/example/dagger/kotlin/AndroidModule.class")
} }
} }
} }
@@ -75,7 +75,7 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("kt15001", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("kt15001", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("compileReleaseSources", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
} }
@@ -86,13 +86,13 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("android-dbflow", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("android-dbflow", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("compileReleaseSources", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
assertFileExists("app/build/generated/source/kapt/release/com/raizlabs/android/dbflow/config/GeneratedDatabaseHolder.java") assertFileExists("app/build/generated/source/kapt/debug/com/raizlabs/android/dbflow/config/GeneratedDatabaseHolder.java")
assertFileExists("app/build/generated/source/kapt/release/com/raizlabs/android/dbflow/config/AppDatabaseapp_Database.java") assertFileExists("app/build/generated/source/kapt/debug/com/raizlabs/android/dbflow/config/AppDatabaseapp_Database.java")
assertFileExists("app/build/generated/source/kapt/release/mobi/porquenao/poc/kotlin/core/Item_Table.java") assertFileExists("app/build/generated/source/kapt/debug/mobi/porquenao/poc/kotlin/core/Item_Table.java")
assertFileExists("app/build/generated/source/kapt/release/mobi/porquenao/poc/kotlin/core/Item_Adapter.java") assertFileExists("app/build/generated/source/kapt/debug/mobi/porquenao/poc/kotlin/core/Item_Adapter.java")
} }
} }
@@ -101,13 +101,13 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("android-realm", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("android-realm", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("compileReleaseSources", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
assertFileExists("build/generated/source/kapt/release/io/realm/CatRealmProxy.java") assertFileExists("build/generated/source/kapt/debug/io/realm/CatRealmProxy.java")
assertFileExists("build/generated/source/kapt/release/io/realm/CatRealmProxyInterface.java") assertFileExists("build/generated/source/kapt/debug/io/realm/CatRealmProxyInterface.java")
assertFileExists("build/generated/source/kapt/release/io/realm/DefaultRealmModule.java") assertFileExists("build/generated/source/kapt/debug/io/realm/DefaultRealmModule.java")
assertFileExists("build/generated/source/kapt/release/io/realm/DefaultRealmModuleMediator.java") assertFileExists("build/generated/source/kapt/debug/io/realm/DefaultRealmModuleMediator.java")
} }
} }
@@ -116,11 +116,11 @@ open class Kapt3AndroidIT : Kapt3BaseIT() {
val project = Project("android-databinding", GRADLE_VERSION, directoryPrefix = "kapt2") val project = Project("android-databinding", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions() val options = androidBuildOptions()
project.build("compileReleaseSources", options = options) { project.build("assembleDebug", options = options) {
assertSuccessful() assertSuccessful()
assertKaptSuccessful() assertKaptSuccessful()
assertFileExists("app/build/generated/source/kapt/release/com/example/databinding/BR.java") assertFileExists("app/build/generated/source/kapt/debug/com/example/databinding/BR.java")
assertFileExists("app/build/generated/source/kapt/release/com/example/databinding/databinding/ActivityTestBinding.java") assertFileExists("app/build/generated/source/kapt/debug/com/example/databinding/databinding/ActivityTestBinding.java")
} }
} }
} }
@@ -42,14 +42,14 @@ class UpToDateIT : BaseGradleIT() {
} }
private fun testMutations(vararg mutations: ProjectMutation) { private fun testMutations(vararg mutations: ProjectMutation) {
val project = Project("simpleProject") val project = Project("kotlinProject")
project.setupWorkingDir() project.setupWorkingDir()
mutations.forEach { mutations.forEach {
it.initProject(project) it.initProject(project)
project.build("build") { assertSuccessful() } project.build("classes") { assertSuccessful() }
it.mutateProject(project) it.mutateProject(project)
project.build("build") { project.build("classes") {
try { try {
assertSuccessful() assertSuccessful()
it.checkAfterRebuild(this) it.checkAfterRebuild(this)