Skip to content

Commit 6b948f8

Browse files
authored
Merge pull request #20 from zbynek/master
Add download task for instrumentation test only
2 parents fcd2efa + 58d89d6 commit 6b948f8

File tree

2 files changed

+57
-88
lines changed

2 files changed

+57
-88
lines changed

plugin/src/main/java/com/appunite/firebasetestlabplugin/FirebaseTestLabPlugin.kt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.gradle.api.Task
2020
import org.gradle.api.tasks.Exec
2121
import org.gradle.kotlin.dsl.closureOf
2222
import org.gradle.kotlin.dsl.register
23+
import groovy.lang.Closure
2324
import java.io.ByteArrayOutputStream
2425
import java.io.File
2526
import java.io.Serializable
@@ -48,6 +49,8 @@ class FirebaseTestLabPlugin : Plugin<Project> {
4849
private const val taskAuth = "firebaseTestLabAuth"
4950
private const val taskSetup = "firebaseTestLabSetup"
5051
private const val taskSetProject = "firebaseTestLabSetProject"
52+
private const val taskPrefixDownload = "firebaseTestLabDownload"
53+
private const val taskPrefixExecute = "firebaseTestLabExecute"
5154
}
5255

5356
private lateinit var project: Project
@@ -217,10 +220,10 @@ class FirebaseTestLabPlugin : Plugin<Project> {
217220

218221
val cleanTask = "firebaseTestLabClean${variantName.capitalize()}"
219222

220-
val runTestsTask = "firebaseTestLabExecute${variantName.capitalize()}"
223+
val variantSuffix = variantName.capitalize()
224+
val runTestsTask = taskPrefixExecute + variantSuffix
221225
val runTestsTaskInstrumentation = "${runTestsTask}Instrumentation"
222226
val runTestsTaskRobo = "${runTestsTask}Robo"
223-
val downloadTask = "firebaseTestLabDownload${variantName.capitalize()}"
224227

225228
if (downloader != null) {
226229
project.task(cleanTask, closureOf<Task> {
@@ -403,17 +406,19 @@ class FirebaseTestLabPlugin : Plugin<Project> {
403406
})
404407

405408
if (downloader != null) {
406-
project.task(downloadTask, closureOf<Task> {
407-
group = Constants.FIREBASE_TEST_LAB
408-
description = "Run Android Tests in Firebase Test Lab and download artifacts from google storage"
409-
dependsOn(taskSetup)
410-
dependsOn(runTestsTask)
411-
mustRunAfter(cleanTask)
409+
listOf(variantSuffix, "${variantSuffix}Instrumentation").map{suffix ->
410+
project.task(taskPrefixDownload + suffix, closureOf<Task> {
411+
group = Constants.FIREBASE_TEST_LAB
412+
description = "Run Android Tests in Firebase Test Lab and download artifacts from google storage"
413+
dependsOn(taskSetup)
414+
dependsOn(taskPrefixExecute + suffix)
415+
mustRunAfter(cleanTask)
412416

413-
doLast {
414-
downloader.getResults()
415-
}
416-
})
417+
doLast {
418+
downloader.getResults()
419+
}
420+
})
421+
}
417422
}
418423
}
419424

@@ -446,4 +451,4 @@ private fun <T1, T2, R> combineAll(l1: Collection<T1>, l2: Collection<T2>, func:
446451
l1.flatMap { t1 -> l2.map { t2 -> func(t1, t2)} }
447452

448453
fun dashToCamelCase(dash: String): String =
449-
dash.split('-', '_').joinToString("") { it.capitalize() }
454+
dash.split('-', '_').joinToString("") { it.capitalize() }

plugin/src/test/java/com/appunite/firebasetestlabplugin/IntegrationTest.kt

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import java.io.File
1212

1313
class IntegrationTest {
1414

15-
@Test
16-
fun `test evaluate simple project success`() {
15+
fun prepareSimpleProject(): Project {
1716
val simpleProject = File(javaClass.getResource("simple").file)
1817
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
1918
project.plugins.apply("com.android.application")
20-
19+
2120
project.configure<AppExtension> {
2221
compileSdkVersion(27)
2322
defaultConfig.apply {
@@ -27,6 +26,13 @@ class IntegrationTest {
2726
setTargetSdkVersion(27)
2827
}
2928
}
29+
return project
30+
}
31+
32+
33+
@Test
34+
fun `test evaluate simple project success`() {
35+
val project = prepareSimpleProject()
3036
(project as ProjectInternal).evaluate()
3137
}
3238

@@ -50,18 +56,8 @@ class IntegrationTest {
5056
@Test
5157
fun `run firebaseTestLabSetup install gcloud`() {
5258
val simpleProject = File(javaClass.getResource("simple").file)
53-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
54-
project.plugins.apply("com.android.application")
55-
project.plugins.apply("firebase.test.lab")
56-
project.configure<AppExtension> {
57-
compileSdkVersion(27)
58-
defaultConfig.also {
59-
it.versionCode = 1
60-
it.versionName = "0.1"
61-
it.setMinSdkVersion(27)
62-
it.setTargetSdkVersion(27)
63-
}
64-
}
59+
val project = prepareSimpleProject()
60+
project.plugins.apply("firebase.test.lab")
6561
project.configure<FirebaseTestLabPluginExtension> {
6662
googleProjectId = "test"
6763
keyFile = File(simpleProject, "key.json")
@@ -75,18 +71,8 @@ class IntegrationTest {
7571
@Test
7672
fun `ensure after evaluation tasks presented`() {
7773
val simpleProject = File(javaClass.getResource("simple").file)
78-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
79-
project.plugins.apply("com.android.application")
80-
project.plugins.apply("firebase.test.lab")
81-
project.configure<AppExtension> {
82-
compileSdkVersion(27)
83-
defaultConfig.also {
84-
it.versionCode = 1
85-
it.versionName = "0.1"
86-
it.setMinSdkVersion(27)
87-
it.setTargetSdkVersion(27)
88-
}
89-
}
74+
val project = prepareSimpleProject()
75+
project.plugins.apply("firebase.test.lab")
9076
project.configure<FirebaseTestLabPluginExtension> {
9177
googleProjectId = "test"
9278
keyFile = File(simpleProject, "key.json")
@@ -96,25 +82,36 @@ class IntegrationTest {
9682
}
9783
(project as ProjectInternal).evaluate()
9884

99-
10085
assertTrue(project.getTasksByName("firebaseTestLabExecuteDebugInstrumentation", false).isNotEmpty())
10186
assertTrue(project.getTasksByName("firebaseTestLabExecuteDebugRobo", false).isNotEmpty())
10287
}
10388

89+
@Test
90+
fun `ensure after evaluation download tasks presented`() {
91+
val simpleProject = File(javaClass.getResource("simple").file)
92+
val project = prepareSimpleProject()
93+
project.plugins.apply("firebase.test.lab")
94+
project.configure<FirebaseTestLabPluginExtension> {
95+
googleProjectId = "test"
96+
cloudBucketName = "test-bucket"
97+
cloudDirectoryName = "test-directory"
98+
keyFile = File(simpleProject, "key.json")
99+
createDevice("myDevice") {
100+
deviceIds = listOf("Nexus6")
101+
}
102+
}
103+
(project as ProjectInternal).evaluate()
104+
105+
assertTrue(project.getTasksByName("firebaseTestLabDownloadDebugInstrumentation", false).isNotEmpty())
106+
assertTrue(project.getTasksByName("firebaseTestLabDownloadDebug", false).isNotEmpty())
107+
}
108+
104109
@Test
105110
fun `ensure tasks are created for abi splits with universal apk`() {
106111
val simpleProject = File(javaClass.getResource("simple").file)
107-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
108-
project.plugins.apply("com.android.application")
112+
val project = prepareSimpleProject()
109113
project.plugins.apply("firebase.test.lab")
110114
project.configure<AppExtension> {
111-
compileSdkVersion(27)
112-
defaultConfig.also {
113-
it.versionCode = 1
114-
it.versionName = "0.1"
115-
it.setMinSdkVersion(27)
116-
it.setTargetSdkVersion(27)
117-
}
118115
splits.also {
119116
it.abi.also {
120117
it.isEnable = true
@@ -143,17 +140,9 @@ class IntegrationTest {
143140
@Test
144141
fun `ensure tasks are created for abi splits without unversal apk`() {
145142
val simpleProject = File(javaClass.getResource("simple").file)
146-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
147-
project.plugins.apply("com.android.application")
143+
val project = prepareSimpleProject()
148144
project.plugins.apply("firebase.test.lab")
149145
project.configure<AppExtension> {
150-
compileSdkVersion(27)
151-
defaultConfig.also {
152-
it.versionCode = 1
153-
it.versionName = "0.1"
154-
it.setMinSdkVersion(27)
155-
it.setTargetSdkVersion(27)
156-
}
157146
splits.also {
158147
it.abi.also {
159148
it.isEnable = true
@@ -182,17 +171,9 @@ class IntegrationTest {
182171
@Test
183172
fun `ensure tasks are created for abi splits with filter`() {
184173
val simpleProject = File(javaClass.getResource("simple").file)
185-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
186-
project.plugins.apply("com.android.application")
174+
val project = prepareSimpleProject()
187175
project.plugins.apply("firebase.test.lab")
188176
project.configure<AppExtension> {
189-
compileSdkVersion(27)
190-
defaultConfig.also {
191-
it.versionCode = 1
192-
it.versionName = "0.1"
193-
it.setMinSdkVersion(27)
194-
it.setTargetSdkVersion(27)
195-
}
196177
splits.also {
197178
it.abi.also {
198179
it.isEnable = true
@@ -224,17 +205,9 @@ class IntegrationTest {
224205
@Test
225206
fun `ensure tasks are created for abi splits with filter all`() {
226207
val simpleProject = File(javaClass.getResource("simple").file)
227-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
228-
project.plugins.apply("com.android.application")
208+
val project = prepareSimpleProject()
229209
project.plugins.apply("firebase.test.lab")
230210
project.configure<AppExtension> {
231-
compileSdkVersion(27)
232-
defaultConfig.also {
233-
it.versionCode = 1
234-
it.versionName = "0.1"
235-
it.setMinSdkVersion(27)
236-
it.setTargetSdkVersion(27)
237-
}
238211
splits.also {
239212
it.abi.also {
240213
it.isEnable = true
@@ -264,18 +237,9 @@ class IntegrationTest {
264237
@Test
265238
fun `ensure tasks are created when abi split is disabled`() {
266239
val simpleProject = File(javaClass.getResource("simple").file)
267-
val project = ProjectBuilder.builder().withProjectDir(simpleProject).build()
268-
project.plugins.apply("com.android.application")
240+
val project = prepareSimpleProject()
269241
project.plugins.apply("firebase.test.lab")
270-
project.configure<AppExtension> {
271-
compileSdkVersion(27)
272-
defaultConfig.also {
273-
it.versionCode = 1
274-
it.versionName = "0.1"
275-
it.setMinSdkVersion(27)
276-
it.setTargetSdkVersion(27)
277-
}
278-
}
242+
279243
project.configure<FirebaseTestLabPluginExtension> {
280244
googleProjectId = "test"
281245
keyFile = File(simpleProject, "key.json")

0 commit comments

Comments
 (0)