Hi, I am searching for an assertion library, which...
# getting-started
p
Hi, I am searching for an assertion library, which is kind of hassle free. What I mean, that I shouldn't add clues for nice assertion error messages. Something similar to FluentAssertions for dotnet.
```string accountNumber = "1234567890";
accountNumber.Should().Be("0987654321");```
This will be reported as:
Expected accountNumber to be “0987654321”, but “1234567890” differs near “123” (index 0).
```var numbers = new[] { 1, 2, 3 };
numbers.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);```
will fail with:
Expected numbers to have an item matching (item > 3) because at least 1 item should be larger than 3.
c
Have you read about https://strikt.io/ ?
#strikt
p
Well, looking into it. Trying to convert this assertj assertions:
Copy code
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
assertThat(entity.body).contains("version")
almost there, but a bit harder to write
Copy code
expectThat(entity) {
    get(ResponseEntity<String>::statusCode).isEqualTo(HttpStatus.OK)
    get(ResponseEntity<String>::getBody). ??
}
But not as smooth as:
Copy code
obj.Property.Should().BeEquivalentTo(expected)
in dotnet, where it will report the name
obj
and property
Property
in the failure message.
Cool, this seems to be similar: https://strikt.io/wiki/traversing-subjects/#using-get-with-lambdas
```val subject = Person(name = "David", birthDate = LocalDate.of(1947, 1, 8))
expectThat(subject) {
get { name }.isEqualTo("Ziggy")
get { birthDate.year }.isEqualTo(1971)
}
---
▼ Expect that Person(name=David, birthDate=1947-01-08):
▼ name:
✗ is equal to "Ziggy"
found "David"
▼ birthDate.year:
✗ is equal to 1971
found 1947```
c
#kotest's standard assertions are
x shouldBe y