Skip to content

Commit 9695576

Browse files
authored
Use square brackets for parameterized tests to ensure that their logs show correctly (#351)
1 parent b26fbf8 commit 9695576

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

instrumentation/runner/src/main/kotlin/de/mannodermaus/junit5/internal/formatters/TestNameFormatter.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ internal object TestNameFormatter {
3737
}
3838
}
3939

40-
return identifier.displayName.replace("()", "")
40+
// Process the display name before handing it out,
41+
// maintaining compatibility with the expectations of Android's instrumentation:
42+
// - Cut off no-parameter brackets '()'
43+
// - Replace any other round brackets with square brackets (for parameterized tests)
44+
// to ensure that logs are displayed in the test results window (ref. #350)
45+
return identifier.displayName
46+
.replace("()", "")
47+
.replace('(', '[')
48+
.replace(')', ']')
4149
}
4250
}

instrumentation/runner/src/test/kotlin/de/mannodermaus/junit5/internal/formatters/TestNameFormatterTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestNameFormatterTests {
2626

2727
@Test
2828
fun `repeated test`() = runTestWith(HasRepeatedTest::class) { identifier ->
29-
assertThat(identifier.format(false)).isEqualTo("method(RepetitionInfo)")
29+
assertThat(identifier.format(false)).isEqualTo("method[RepetitionInfo]")
3030
assertThat(identifier.format(true)).isEqualTo("method")
3131

3232
// Inspect individual executions, too
@@ -52,7 +52,7 @@ class TestNameFormatterTests {
5252

5353
@Test
5454
fun `test template`() = runTestWith(HasTestTemplate::class) { identifier ->
55-
assertThat(identifier.format(false)).isEqualTo("method(String)")
55+
assertThat(identifier.format(false)).isEqualTo("method[String]")
5656
assertThat(identifier.format(true)).isEqualTo("method")
5757

5858
// Inspect individual executions, too
@@ -65,7 +65,7 @@ class TestNameFormatterTests {
6565

6666
@Test
6767
fun `parameterized test`() = runTestWith(HasParameterizedTest::class) { identifier ->
68-
assertThat(identifier.format(false)).isEqualTo("method(String)")
68+
assertThat(identifier.format(false)).isEqualTo("method[String]")
6969
assertThat(identifier.format(true)).isEqualTo("method")
7070

7171
// Inspect individual executions, too

instrumentation/runner/src/test/kotlin/de/mannodermaus/junit5/internal/runners/AndroidJUnitPlatformTestTreeTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AndroidJUnitPlatformTestTreeTests {
2727
}
2828

2929
@CsvSource(
30-
"false, method(RepetitionInfo) - repetition %d of 5",
30+
"false, method[RepetitionInfo] - repetition %d of 5",
3131
"true, method[%d]",
3232
)
3333
@ParameterizedTest
@@ -62,7 +62,7 @@ class AndroidJUnitPlatformTestTreeTests {
6262
}
6363

6464
@CsvSource(
65-
"false, method(String) - %s",
65+
"false, method[String] - %s",
6666
"true, method[%d]",
6767
)
6868
@ParameterizedTest
@@ -83,7 +83,7 @@ class AndroidJUnitPlatformTestTreeTests {
8383
}
8484

8585
@CsvSource(
86-
"false, method(String) - [%d] %s",
86+
"false, method[String] - [%d] %s",
8787
"true, method[%d]",
8888
)
8989
@ParameterizedTest

0 commit comments

Comments
 (0)