-
I'm migrating from AssertJ, with following asserting method chaining:
However, in AssertK - this is not possible, because What's the reasoning for this? P.S. I know that there is an alternative |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
While method chaining can be useful it can also be confusing when it's used it different ways in different places. We chose to use chaining only to narrow what's being asserted on. This way each method in the chain is relevant to the one before it. For example: assertThat(person).isNotNull().prop(Person::name).isEqualTo(...) We go As you mentioned, when you want to have multiple assertions on the same value, you can use assertThat(array).all {
hasSize(2)
isEqualTo(...)
} One note: assertThat(array).apply {
hasSize(2)
isEqualTo(...)
}
That's fair. Though while this library was inspired by assertj, having 1-1 feature parity to make migration easy was never a goal. |
Beta Was this translation helpful? Give feedback.
While method chaining can be useful it can also be confusing when it's used it different ways in different places. We chose to use chaining only to narrow what's being asserted on. This way each method in the chain is relevant to the one before it. For example:
We go
Person?
->Person
->String
.As you mentioned, when you want to have multiple assertions on the same value, you can use
all
and it's clear what you are doing and still quite conciseOne note:
all
and it's counterpartassertAll
do work differently than a chain in assertj in that they use soft assertions. So if