How to compile Kotlin unit test code that uses hamcrest 'is'

后端 未结 3 1887
孤独总比滥情好
孤独总比滥情好 2021-02-12 02:55

I want to write a unit test for my Kotlin code and use junit/hamcrest matchers, I want to use the is method, but it is a reserved word in Kotlin.

How can I

3条回答
  •  不知归路
    2021-02-12 03:36

    In Kotlin, is is a reserved word . To get around this you need to escape the code using backticks, so the following will allow you to compile the code:

    class testExample{
      @Test fun example(){
        assertThat(1, `is`(equalTo(1))
      }
    }
    

提交回复
热议问题