What is your favorite assertion library for Kotlin?

4.5 years ago I asked what your favorite assertion library is. Things have changed in the meantime and such a library is an important tool for daily usage.

So, what is your favorite assertion library for Kotlin now? Maybe you could also share, why do you prefer the library you picked (bonus points for that answer! :wink: )

I have used strikt in the past, because of its nice syntax and plenty assertions.

Nowadays kotest (formerly kotlintest, not te be confused with kotlin-test) seems to have caught up on the assertions part, so I’m giving this a try in some projects. It also has its own (optional) test runner with plenty of writing-styles and features - one thing I found, though, is that I can’t run specific tests via the IntelliJ gutter (there is an kotest IntelliJ plugin which brings back the icons, but the tests aren’t run via Gradle).

Kotest hands down. A while ago I made a comparison of assertion libs features, hope that would be useful for someone.

2 Likes

Let me share some recent experiences with Strikt. While the Kotlin friendly syntax looks very nice, this library struggles with the basis. AssertJ, what is the source of inspiration for Strikt, supports a very handy method usingRecursiveFieldByFieldElementComparatorIgnoringFields to compare complete objects except certain fields (e.g. IDs). Strikt doesn’t seem to have such a function. containsExcactly to compare lists should be there, according to the documentation, but isn’t.