Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Commit 984b64f

Browse files
CristianGMartem-zinnatullin
authored andcommitted
Install extra APKs if received ( useful for Orchestrator ) (#159)
Now that we allow to use Orchestrator it would be nice to install the APKs required by Orchestrator to run. Instead of being specific for Orchestrator this PR allows devs to install any extra APK they need. ~~There are no tests or documentation written yet because I want to validate the approach taken first, if it's ok I'll update the docs and add some tests ( suggestions on which ones are welcomed )~~
1 parent d200b1c commit 984b64f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ Composer shipped as jar, to run it you need JVM 1.8+: `java -jar composer-latest
126126
* Requires test orchestrator & test services APKs to be installed on device before executing.
127127
* More info: https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator
128128
* Example: `--with-orchestrator true`
129+
* `--extra-apks`
130+
* Apks to be installed for utilities. What you would typically declare in gradle as `androidTestUtil`
131+
* Default: empty, only apk and test apk would be installed.
132+
* Works great with Orchestrator to install orchestrator & test services APKs.
133+
* Example: `--extra-apks path/to/apk/first.apk path/to/apk/second.apk`
129134

130135
##### Example
131136

composer/src/main/kotlin/com/gojuno/composer/Args.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ data class Args(
114114
description = "Either `true` or `false` to enable/disable running tests via Android Test Orchestrator. False by default.",
115115
order = 12
116116
)
117-
var runWithOrchestrator: Boolean = false
117+
var runWithOrchestrator: Boolean = false,
118+
119+
@Parameter(
120+
names = arrayOf("--extra-apks"),
121+
required = false,
122+
variableArity = true,
123+
description = "Extra APKs you would usually put on androidTestUtil",
124+
order = 13
125+
)
126+
var extraApks: List<String> = emptyList()
118127
)
119128

120129
// No way to share array both for runtime and annotation without reflection.
@@ -141,4 +150,4 @@ fun parseArgs(rawArgs: Array<String>) = Args().also { args ->
141150

142151
private class InstrumentationArgumentsConverter : IStringConverter<List<String>> {
143152
override fun convert(argument: String): List<String> = listOf(argument)
144-
}
153+
}

composer/src/main/kotlin/com/gojuno/composer/Main.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner:
111111
val installTimeout = Pair(args.installTimeoutSeconds, TimeUnit.SECONDS)
112112
val installAppApk = device.installApk(pathToApk = args.appApkPath, timeout = installTimeout)
113113
val installTestApk = device.installApk(pathToApk = args.testApkPath, timeout = installTimeout)
114+
val installApks = mutableListOf(installAppApk, installTestApk)
115+
installApks.addAll(args.extraApks.map {
116+
device.installApk(pathToApk = it, timeout = installTimeout)
117+
})
114118

115119
Observable
116-
.concat(installAppApk, installTestApk)
120+
.concat(installApks)
117121
// Work with each device in parallel, but install apks sequentially on a device.
118122
.subscribeOn(Schedulers.io())
119123
.toList()

composer/src/test/kotlin/com/gojuno/composer/ArgsSpec.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class ArgsSpec : Spek({
3131
devicePattern = "",
3232
installTimeoutSeconds = 120,
3333
failIfNoTests = true,
34-
runWithOrchestrator = false
34+
runWithOrchestrator = false,
35+
extraApks = emptyList()
3536
))
3637
}
3738
}
@@ -205,4 +206,16 @@ class ArgsSpec : Spek({
205206
assertThat(args.runWithOrchestrator).isEqualTo(true)
206207
}
207208
}
209+
210+
context("parse args with passed --extra-apks") {
211+
212+
val args by memoized {
213+
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--extra-apks", "apk1.apk", "apk2.apk"))
214+
}
215+
216+
it("parses correctly two extra apks") {
217+
assertThat(args.extraApks).isEqualTo(listOf("apk1.apk", "apk2.apk"))
218+
}
219+
}
220+
208221
})

0 commit comments

Comments
 (0)