Is there a Kotlin equivalent for AssertJ library?

I am converting some tests from Java to Kotlin. For Java tests, I use the AssertJ library, which is very powerful and has a rich set of statements. My problem is that for Kotlin tests I cannot use AssertJ and Kotlin JUnit ( org.jetbrains.kotlin:kotlin-test-junit) has a very limited set of statements.

Is there a Kotlin equivalent for AssertJ or a better way for claims?

I found the Kluent library , but I'm still not sure if this is the best library to use.

+4
source share
2 answers

There is no official equivalent, but basic AssertJ is still used in many cases and looks pretty good:

assertThat(info)
  .containsKey("foo")


assertThatThrownBy { session.restTemplate.postForLocation("foo", {}) }
  .isExactlyInstanceOf(HttpClientErrorException::class.java)

If you need special wrappers, this project is at an early stage trying to achieve this: https://github.com/wuan/assertj-core-kotlin

+4
source

You are probably no longer looking for a claims library, but in case you are not satisfied with your current choice, see https://github.com/robstoll/atrium

It supports, among other things:

  • claim groups
  • assertion functions for nullable types
  • property approvals
  • method approvals
  • postulate that the throwable has been cast.

The examples in README will give you a good overview: https://github.com/robstoll/atrium/blob/master/README.md#examples

+4

Source: https://habr.com/ru/post/1683805/


All Articles