Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support additional-app-test-apks #83

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fladle {
flankVersion("4.4.0")
debugApk("$buildDir/outputs/apk/debug/sample-debug.apk")
instrumentationApk("$buildDir/outputs/apk/androidTest/debug/sample-debug-androidTest.apk"
additionalTestApks = ["$buildDir/outputs/apk/debug/sample-debug.apk": ["$buildDir/outputs/apk/androidTest/debug/sample2-debug-androidTest.apk"]]
autoGoogleLogin = true
testShards = 5
smartFlankGcsPath = "gs://tmp_flank/flank/test_app_android.xml"
Expand Down Expand Up @@ -121,6 +122,9 @@ This is the path to the app's debug apk.
### instrumentationApk
This is the path to the app's instrumentation apk.

### additionalTestApks
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a short sample? and that it is a map of debug apks to a list of instrumentation apks? thanks :)

Paths to additional test configurations.

### autoGoogleLogin
Whether or not to automatically log in using a preconfigured google account. [More Info](https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run#--auto-google-login)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ interface FladleConfig {
* (default: a timestamp with a random suffix).
*/
var resultsDir: String?

var additionalTestApks: Map<String, List<String>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ data class FladleConfigImpl(
override var performanceMetrics: Boolean = true,
override var resultsBucket: String? = null,
override var keepFilePath: Boolean = false,
override var resultsDir: String?
override var resultsDir: String?,
override var additionalTestApks: Map<String, List<String>> = emptyMap()
) : FladleConfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ open class FlankGradleExtension(project: Project) : FladleConfig {
override var keepFilePath: Boolean = false

override var resultsDir: String? = null

override var additionalTestApks: Map<String, List<String>> = emptyMap()

val configs: NamedDomainObjectContainer<FladleConfigImpl> = project.container(FladleConfigImpl::class.java) {
FladleConfigImpl(
name = it,
Expand All @@ -74,7 +77,8 @@ open class FlankGradleExtension(project: Project) : FladleConfig {
performanceMetrics = performanceMetrics,
resultsBucket = resultsBucket,
keepFilePath = keepFilePath,
resultsDir = resultsDir
resultsDir = resultsDir,
additionalTestApks = additionalTestApks
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class FlankGradlePlugin : Plugin<Project> {
}
checkNotNull(base.debugApk!!) { "debugApk file cannot be null ${base.debugApk}" }
checkNotNull(base.instrumentationApk!!) { "instrumentationApk file cannot be null ${base.instrumentationApk}" }
base.additionalTestApks.forEach {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

check(it.value.isNotEmpty()) { "must provide at least one instrumentation apk for ${it.key}" }
}
}

private fun automaticallyConfigureTestOrchestrator(project: Project, extension: FlankGradleExtension, androidExtension: AppExtension) {
Expand Down
11 changes: 11 additions & 0 deletions buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ internal class YamlWriter {
appendln(" - $file")
}
}
val testApks = config.additionalTestApks.flatMap { (debugApk, instrumentationApks) ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code can be somewhat simplified a bit since the instrumentation apk will take whatever value is above is as the debug apk. See the readme. https://github.com/TestArmada/flank/blob/master/README.md

if (config.additionalTestApks.isNotEmpty()) {
  appendln("  additional-app-test-apks:")
  config.additionalTestApks.entries.forEach { debugApk, instrumentationApks ->
    appendln("    - app: ${debugApk}")
    instrumentationApks.forEach {
        appendln("    test: ${it}")
    }
  }

On the other hand, I do like the more explicit output format that you created here. Let me think this one over overnight. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change this?

instrumentationApks.map { debugApk to it }
}

if (testApks.isNotEmpty()) {
appendln(" additional-app-test-apks:")
testApks.forEach {
appendln(" - app: ${it.first}")
appendln(" test: ${it.second}")
}
}
}

internal fun writeAdditionalProperties(config: FladleConfig): String = buildString {
Expand Down
27 changes: 27 additions & 0 deletions buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.osacky.flank.gradle

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Assert.assertEquals
import org.junit.Assert.fail
import org.junit.Before
Expand Down Expand Up @@ -584,4 +586,29 @@ class YamlWriterTest {
" keep-file-path: true\n",
yamlWriter.writeFlankProperties(extension))
}

@Test
fun writeAdditionalTestApks() {
val extension = FlankGradleExtension(project).apply {
debugApk = "../orange/build/output/app.apk"
instrumentationApk = "../orange/build/output/app-test.apk"
additionalTestApks = mapOf(
"../orange/build/output/app.apk" to listOf("../orange/build/output/app-test2.apk"),
"../bob/build/output/app.apk" to listOf("../bob/build/output/app-test.apk")
)
}

assertThat(
yamlWriter.writeFlankProperties(extension),
equalTo(
"flank:\n" +
" keep-file-path: false\n" +
" additional-app-test-apks:\n" +
" - app: ../orange/build/output/app.apk\n" +
" test: ../orange/build/output/app-test2.apk\n" +
" - app: ../bob/build/output/app.apk\n" +
" test: ../bob/build/output/app-test.apk\n"
)
)
}
}