Skip to content

Commit

Permalink
Disable window animation in tests by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-goral authored and mergify-bot committed Jun 1, 2021
1 parent 6e76e61 commit ba0570f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,34 @@ package flank.instrument.command
* "package package.name"
* ```
*
* @param packageName the package name of the android test apk.
* @param testRunner the test runner full name.
* @param testCases the list of test cases names.
* @param packageName The package name of the android test apk.
* @param testRunner The test runner full name.
* @param testCases The list of test cases names.
* @param noWindowAnimation Adds `--no-window-animation` to command.
*/
fun formatAmInstrumentCommand(
packageName: String,
testRunner: String,
testCases: List<String>,
noWindowAnimation: Boolean = true,
): String {
val testCasesChunk = testCases // example: listOf("class foo.Bar#baz")
.map { it.split(" ") } // example: listOf(listOf("class", "foo.Bar#baz"))
.groupBy({ it.first() }, { it.last() }) // example: first => "class", last => "foo.Bar#baz"
.toList().joinToString("") { (type, tests: List<String>) ->
"-e $type ${tests.joinToString(",")} " // example: "-e class foo.Bar#baz"
} // example: "-e class foo.Bar#baz1,foo.Bar#baz2 -e package foo.test "
}.trimEnd() // example: "-e class foo.Bar#baz1,foo.Bar#baz2 -e package foo.test"

val runnerChunk = "$packageName/$testRunner"

// example: "am instrument -r -w -e class foo.Bar#baz foo.test/androidx.test.runner.AndroidJUnitRunner"
return AM_INSTRUMENT + testCasesChunk + runnerChunk
// example: "am instrument -r -w --no-window-animation -e class foo.Bar#baz foo.test/androidx.test.runner.AndroidJUnitRunner"
return listOfNotNull(
AM_INSTRUMENT,
NO_WINDOW_ANIMATION.takeIf { noWindowAnimation },
testCasesChunk,
runnerChunk
).joinToString(" ")
}

private const val AM_INSTRUMENT = "am instrument -r -w "
private const val AM_INSTRUMENT = "am instrument -r -w"
private const val NO_WINDOW_ANIMATION = "--no-window-animation"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class FormatAmInstrumentCommandKtTest {
@Test
fun test() {
val expected = "am instrument -r -w" +
" --no-window-animation" +
" -e class com.package.Test1#testMethod1,com.package.Test2#testMethod1,com.package.Test2#testMethod2" +
" -e package com.package.nested1,com.package.nested2 com.package/AnyRunner"

Expand All @@ -20,7 +21,8 @@ class FormatAmInstrumentCommandKtTest {
"class com.package.Test2#testMethod2",
"package com.package.nested1",
"package com.package.nested2",
)
),
// noWindowAnimation = true, // No window animation should be disable by default
)

assertEquals(expected, actual)
Expand Down

0 comments on commit ba0570f

Please sign in to comment.