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

后端 未结 3 1735
清歌不尽
清歌不尽 2021-02-12 02:36

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:17

    You can alias is (say to Is) when you import, using the as keyword.

    E.g:

     import org.hamcrest.CoreMatchers.`is` as Is
    

    See https://kotlinlang.org/docs/reference/packages.html

提交回复
热议问题