[Kotlin]SoftAssertions with Kotlin and AssertJ

Hi there,

Do you know soft assertions provided by AssertJ?

In many cases, one test case has one assertion.
But sometimes we’d like to collect some assertions within one assertion, and then we can use SoftAssertions() for the purpose.

Of course, we can use AssertJ in JUnit. In addition, we can use it in Kotlin like the following.

SoftAssertions().apply {
  assertThat(1 + 1).isEqualTo(1)
  assertThat(1 + 3).isEqualTo(2)
  assertThat(1 + 1).isEqualTo(3)
}.assertAll()

So useful syntax 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s