úterý 1. ledna 2019

Kotlin - Use spaces in name of tests.md

Kotlin - Use spaces in name of tests.md

Kotlin - Use spaces in name of tests

Kotlin allow us to use any characters in method names (even with spaces). If we enclose it in backticks.:
fun `method - name`() {}

It can be very convenient for name of tests. And I think, that we should definitely make use of this opportunity.

Then we can have descriptive names of tests like for example
Spock
have.

Example

We can figure out a lot of example, but will show you just one :)

Consider this simple test:

@Test  
fun `multiplyExact of zero integer should return zero`() {  
    //when  
    val result = Math.multiplyExact(10, 0)  
      
    //then  
    assertThat(result).isEqualTo(0)  
}

It is easier to understand name of test above, than following one:

@Test  
fun multiplyExactOfZeroIntegerShouldReturnZero() { ... }

Where ends the name of method and where starts test description?

Experience

I have never found any problem with method named like this.
IDE (IntelliJ IDEA) have no problem with methods named like this.
And jUnitRunner have no difficulties with this methods as well.

So there is no excuse for writing less readable test names.

Žádné komentáře:

Okomentovat