Some kotlin.test feature requests (DisplayName, Nested, and others)

Here are some features/functionality I would like to see in kotlin.test based on my experience writing Kotlin tests in JUnit 5 and starting on a Kotlin multiplatform project where only the kotlin.test subset is available.

1. Display Names (Required)

I find the @DisplayName annotation useful for classes in Java/JVM to describe what the class is testing. In Kotlin Multiplatform, using backticks does not work as a) Kotlin/JS does not support spaces, and b) Kotlin/Native does not support parenthesis in the names – having the @DisplayName annotation would allow me to set the readable name for the test function.

2. Nested / Grouped Tests (Required)

I also make use of the @Nested annotation in JUnit 5 to group related functionality into a more readable test, such as:

A CodePoint value class
... Can be constructed from codepoints
... ... in the ASCII (Basic Latin) range
... ... in the Basic Multilingual plane
... ... in an extended unicode plane

3. Removing Parenthesis From Test Names (Nice To Have)

When using function names without a @DisplayName annotation, the test framework adds the () from the function, where it is more readable to not include those. In JUnit 5 I can add:

@DisplayNameGeneration(DisplayNameGenerator.Simple::class)

to the top-level test class and it will not include the parameters. It would be nice to have an equivalent for kotlin.test.

4. Hamcrest Style Tests (Nice To Have)

I personally find having the expected value first is confusing and will frequently place them the wrong way around. As such, I prefer the Hamcrest style test syntax:

assertThat(actual, `is`(expected))

It would be nice if that syntax was also available in kotlin.test in addition to the JUnit-style assertions.

1 Like