For #9605 - review: lintUnitTestRunner depends on compile.
See added comments for explanation.master
parent
b60a21c08d
commit
db495784d2
|
@ -18,29 +18,34 @@ private val INVALID_TEST_RUNNERS = setOf(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lint check that ensures unit tests do not specify an invalid test runner. See the error message
|
* A lint check that ensures unit tests do not specify an invalid test runner. See the error message
|
||||||
* for details.
|
* and the suggested replacement class' kdoc for details.
|
||||||
*
|
*
|
||||||
* Related notes:
|
* Performance note: AS indicates this task takes 50ms-100ms to run. This isn't too concerning because
|
||||||
* - The AndroidJUnit4 runner seems to just delegate to robolectric. Since robolectric non-trivially
|
* it's one task and it only runs for unit test compilation. However, if we add additional lint checks,
|
||||||
* increases test runtime, using AndroidJUnit4 in place of RobolectricTestRunner is very misleading
|
* we should considering aggregating them - e.g. this task reads the unit test file tree and we can
|
||||||
* about how the test will change.
|
* combine all of our tasks such that the file tree only needs to be read once - or finding more
|
||||||
|
* optimal solutions - e.g. only running on changed files.
|
||||||
*/
|
*/
|
||||||
open class LintUnitTestRunner : DefaultTask() {
|
open class LintUnitTestRunner : DefaultTask() {
|
||||||
init {
|
init {
|
||||||
group = "Verification"
|
group = "Verification"
|
||||||
description = "Ensures unit tests do not specify an invalid test runner"
|
description = "Ensures unit tests do not specify an invalid test runner"
|
||||||
attachToAssembleUnitTestTasks()
|
attachToCompilationTasks()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun attachToAssembleUnitTestTasks() {
|
private fun attachToCompilationTasks() {
|
||||||
project.gradle.projectsEvaluated { project.tasks.let { tasks ->
|
project.gradle.projectsEvaluated { project.tasks.let { tasks ->
|
||||||
val assembleUnitTestTasks = tasks.filter {
|
// We make compile tasks, rather than assemble tasks, depend on us because some tools,
|
||||||
it.name.startsWith("assemble") && it.name.endsWith("UnitTest")
|
// such as AS' test runner, call the compile task directly rather than going through assemble.
|
||||||
|
val compileUnitTestTasks = tasks.filter {
|
||||||
|
it.name.startsWith("compile") && it.name.contains("UnitTest")
|
||||||
}
|
}
|
||||||
|
compileUnitTestTasks.forEach { it.dependsOn(this@LintUnitTestRunner) }
|
||||||
|
|
||||||
assembleUnitTestTasks.forEach {
|
// To return feedback as early as possible, we run before all compile tasks including
|
||||||
it.dependsOn(this@LintUnitTestRunner)
|
// compiling the application.
|
||||||
}
|
val compileAllTasks = tasks.filter { it.name.startsWith("compile") }
|
||||||
|
compileAllTasks.forEach { it.mustRunAfter(this@LintUnitTestRunner) }
|
||||||
} }
|
} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue