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

feat: Disable window animation in tests by default #1992

Merged
merged 1 commit into from
Jun 1, 2021
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
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