https://kotlinlang.org logo
Title
f

felipepedroso

05/29/2019, 10:58 AM
Is there a way to add a line break when using backticks to name a method? I'm in the middle of a huge refactoring and would like to write a good description on the tests that I'm creating for that. The long names will be gone later with the methods refactoring but it would be nice to have long names for now...
t

tseisel

05/29/2019, 12:03 PM
Nope, line breaks are not allowed. Even spaces should not be used, but are allowed for some reason. Plus, such method names are not allowed on Android, that's why I stick to using underscores and naming conventions such
fun givenX_whenY_thenZ()
.
If you can use JUnit 5, you can rely on the
@DisplayName
annotation and nested tests to make it easier to read. Also, both
KotlinTest
and
Spek
makes it easier to write readable and structured tests.
f

felipepedroso

05/29/2019, 1:24 PM
but even having underscores wouldn't achieve what I wanted
anyway, thanks
r

Ruckus

05/29/2019, 1:39 PM
Even spaces should not be used, but are allowed for some reason
Using spaces is only an issue on Android, and last I heard there is an ongoing effort to correct that. Using spaces is excellent for tests.
i

itbeha

05/30/2019, 1:19 PM
@felipepedroso check out kotlintest’s StringSpec – it's the very first sample, "test with style" on https://github.com/kotlintest/kotlintest