Skip to content

Commit

Permalink
Add --test-runner-class (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschear authored and bootstraponline committed May 30, 2019
1 parent 838bd47 commit d8befee
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ gcloud:
## Monitor and record performance metrics: CPU, memory, network usage, and FPS (game-loop only).
## Enabled by default, use --no-performance-metrics to disable.
# performance-metrics: true

## The fully-qualified Java class name of the instrumentation test runner
## (default: the last name extracted from the APK manifest).
# test-runner-class: com.foo.TestRunner

## A list of one or more test target filters to apply (default: run all test targets).
## Each target filter must be fully qualified with the package name, class name, or test annotation desired.
Expand Down
4 changes: 4 additions & 0 deletions test_runner/flank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ gcloud:
## Enabled by default, use --no-performance-metrics to disable.
# performance-metrics: true

## The fully-qualified Java class name of the instrumentation test runner
## (default: the last name extracted from the APK manifest).
# test-runner-class: com.foo.TestRunner

## A list of one or more test target filters to apply (default: run all test targets).
## Each target filter must be fully qualified with the package name, class name, or test annotation desired.
## Supported test filters by am instrument -e … include:
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AndroidArgs(
val environmentVariables = cli?.environmentVariables ?: androidGcloud.environmentVariables
val directoriesToPull = cli?.directoriesToPull ?: androidGcloud.directoriesToPull
val performanceMetrics = cli?.performanceMetrics ?: cli?.noPerformanceMetrics?.not() ?: androidGcloud.performanceMetrics
val testRunnerClass = cli?.testRunnerClass ?: androidGcloud.testRunnerClass
val testTargets = cli?.testTargets ?: androidGcloud.testTargets.filterNotNull()
val devices = cli?.device ?: androidGcloud.device

Expand Down Expand Up @@ -126,6 +127,7 @@ ${mapToString(environmentVariables)}
directories-to-pull:
${listToString(directoriesToPull)}
performance-metrics: $performanceMetrics
test-runner-class: $testRunnerClass
test-targets:
${listToString(testTargets)}
device:
Expand Down
5 changes: 4 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class AndroidGcloudYmlParams(
@field:JsonProperty("performance-metrics")
val performanceMetrics: Boolean = true,

@field:JsonProperty("test-runner-class")
val testRunnerClass: String? = null,

@field:JsonProperty("test-targets")
val testTargets: List<String?> = emptyList(),

Expand All @@ -40,7 +43,7 @@ class AndroidGcloudYmlParams(
companion object : IYmlKeys {
override val keys = listOf(
"app", "test", "auto-google-login", "use-orchestrator", "environment-variables",
"directories-to-pull", "performance-metrics", "test-targets", "device"
"directories-to-pull", "performance-metrics", "test-runner-class", "test-targets", "device"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class AndroidRunCommand : Runnable {
)
var noPerformanceMetrics: Boolean? = null

@Option(
names = ["--test-runner-class"],
description = ["The fully-qualified Java class name of the instrumentation test runner (default: the last name extracted " +
"from the APK manifest)."]
)
var testRunnerClass: String? = null

@Option(
names = ["--test-targets"],
split = ",",
Expand Down
4 changes: 4 additions & 0 deletions test_runner/src/main/kotlin/ftl/gc/GcAndroidTestMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ object GcAndroidTestMatrix {
.setAppApk(FileReference().setGcsPath(appApkGcsPath))
.setTestApk(FileReference().setGcsPath(testApkGcsPath))

if (args.testRunnerClass != null) {
androidInstrumentation.testRunnerClass = args.testRunnerClass
}

if (args.useOrchestrator) {
androidInstrumentation.orchestratorOption = "USE_ORCHESTRATOR"
}
Expand Down
20 changes: 20 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class AndroidArgsTest {
- /sdcard/screenshots
- /sdcard/screenshots2
performance-metrics: false
test-runner-class: com.foo.TestRunner
test-targets:
- class com.example.app.ExampleUiTest#testPasses
- class com.example.app.ExampleUiTest#testFails
Expand Down Expand Up @@ -163,6 +164,7 @@ class AndroidArgsTest {
assert(environmentVariables, linkedMapOf("clearPackageData" to "true", "randomEnvVar" to "false"))
assert(directoriesToPull, listOf("/sdcard/screenshots", "/sdcard/screenshots2"))
assert(performanceMetrics, false)
assert(testRunnerClass, "com.foo.TestRunner")
assert(
testTargets,
listOf(
Expand Down Expand Up @@ -218,6 +220,7 @@ AndroidArgs
- /sdcard/screenshots
- /sdcard/screenshots2
performance-metrics: false
test-runner-class: com.foo.TestRunner
test-targets:
- class com.example.app.ExampleUiTest#testPasses
- class com.example.app.ExampleUiTest#testFails
Expand Down Expand Up @@ -281,6 +284,7 @@ AndroidArgs
assert(environmentVariables, emptyMap<String, String>())
assert(directoriesToPull, empty)
assert(performanceMetrics, true)
assert(testRunnerClass, null)
assert(testTargets, empty)
assert(devices, listOf(Device("NexusLowRes", "28")))
assert(flakyTestAttempts, 0)
Expand Down Expand Up @@ -514,6 +518,22 @@ AndroidArgs
assertThat(androidArgs.performanceMetrics).isFalse()
}

@Test
fun cli_testRunnerClass() {
val cli = AndroidRunCommand()
CommandLine(cli).parse("--test-runner-class=com.foo.bar.TestRunner")

val yaml = """
gcloud:
app: $appApk
test: $testApk
"""
assertThat(AndroidArgs.load(yaml).testRunnerClass).isNull()

val androidArgs = AndroidArgs.load(yaml, cli)
assertThat(androidArgs.testRunnerClass).isEqualTo("com.foo.bar.TestRunner")
}

@Test
fun cli_environmentVariables() {
val cli = AndroidRunCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class AndroidRunCommandTest {
assertThat(cmd.noUseOrchestrator).isNull()
assertThat(cmd.performanceMetrics).isNull()
assertThat(cmd.noPerformanceMetrics).isNull()
assertThat(cmd.testRunnerClass).isNull()
assertThat(cmd.environmentVariables).isNull()
assertThat(cmd.directoriesToPull).isNull()
assertThat(cmd.device).isNull()
Expand Down Expand Up @@ -169,6 +170,14 @@ class AndroidRunCommandTest {
assertThat(cmd.noPerformanceMetrics).isTrue()
}

@Test
fun testRunnerClass_parse() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse("--test-runner-class=com.foo.bar.TestRunner")

assertThat(cmd.testRunnerClass).isEqualTo("com.foo.bar.TestRunner")
}

@Test
fun environmentVariables_parse() {
val cmd = AndroidRunCommand()
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/test/kotlin/ftl/test/util/TestHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.nio.file.Paths

object TestHelper {

fun assert(actual: Any, expected: Any) =
fun assert(actual: Any?, expected: Any?) =
Truth.assertThat(actual).isEqualTo(expected)

fun getPath(path: String): Path =
Expand Down

0 comments on commit d8befee

Please # to comment.