Skip to content

Commit d66a059

Browse files
committed
test fix
1 parent 09d3d34 commit d66a059

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
199199
private fun filterAndroidTests(project: Project) {
200200
val tracker = DependencyTracker(project, null)
201201
project.tasks.configureEach { task ->
202-
if (task.name.contains("AndroidTest")) {
202+
if (task.name.contains(ANDROID_TEST_PATTERN)) {
203203
tracker.findAllDependents(project).forEach { dependentProject ->
204204
dependentProject.tasks.forEach { dependentTask ->
205205
AffectedModuleDetector.configureTaskGuard(dependentTask)
@@ -237,6 +237,8 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
237237
private const val PLUGIN_JAVA_LIBRARY = "com.android.library"
238238
private const val PLUGIN_KOTLIN = "kotlin"
239239

240+
private const val ANDROID_TEST_PATTERN = "AndroidTest"
241+
240242
private val pluginIds = listOf(
241243
PLUGIN_ANDROID_APPLICATION,
242244
PLUGIN_ANDROID_LIBRARY,

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/InternalTaskType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal enum class InternalTaskType(
2525
),
2626

2727
JVM_TEST(
28-
commandByImpact = "runAffectedUnitTests",
28+
commandByImpact = "", // inner type. This type doesn't registered in gradle
2929
originalGradleCommand = "test",
3030
taskDescription = "Runs all affected unit tests for non Android modules."
3131
)

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import org.junit.Rule
99
import org.junit.Test
1010
import org.junit.rules.TemporaryFolder
1111
import java.lang.IllegalStateException
12+
import org.junit.runner.RunWith
13+
import org.junit.runners.JUnit4
1214

15+
@RunWith(JUnit4::class)
1316
class AffectedModuleDetectorPluginTest {
1417

1518
private companion object {
@@ -168,14 +171,13 @@ class AffectedModuleDetectorPluginTest {
168171
assertThat(jvmTestTask?.group).isEqualTo(AffectedModuleDetectorPlugin.TEST_TASK_GROUP_NAME)
169172
}
170173

171-
172-
173174
@Test
174175
fun `GIVEN affected module detector plugin WHEN registerTestTasks called THEN added all tasks from InternalTaskType`() {
175176
// GIVEN
176177
val configuration = AffectedModuleConfiguration()
177178
rootProject.extensions.add(AffectedModuleConfiguration.name, configuration)
178179
val plugin = AffectedModuleDetectorPlugin()
180+
val availableTaskVariants = 3 // runAffectedAndroidTests, assembleAffectedAndroidTests and runAffectedUnitTests
179181

180182
// WHEN
181183
plugin.registerTestTasks(rootProject)
@@ -184,7 +186,7 @@ class AffectedModuleDetectorPluginTest {
184186
.filter { it.group == AffectedModuleDetectorPlugin.TEST_TASK_GROUP_NAME }
185187

186188
// THEN
187-
assert(testTasks.size == InternalTaskType.values().size)
189+
assert(testTasks.size == availableTaskVariants)
188190
}
189191

190192
@Test
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.dropbox.affectedmoduledetector
2+
3+
import org.junit.Test
4+
import org.junit.runner.RunWith
5+
import org.junit.runners.JUnit4
6+
7+
@RunWith(JUnit4::class)
8+
class InternalTaskTypeTest {
9+
10+
@Test
11+
fun `GIVEN InternalTaskType WHEN JVM_TEST WHEN THEN originalGradleCommand is "test"`() {
12+
// GIVEN
13+
val nonAndroidTestTask = InternalTaskType.JVM_TEST.originalGradleCommand
14+
val nonAndroidTestCommand = "test"
15+
16+
assert(nonAndroidTestTask == nonAndroidTestCommand)
17+
}
18+
}

0 commit comments

Comments
 (0)