Pihentagy
06/27/2023, 11:58 AM```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.
CLOVIS
06/27/2023, 12:03 PMCLOVIS
06/27/2023, 12:04 PMPihentagy
06/27/2023, 12:34 PMassertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
assertThat(entity.body).contains("version")
almost there, but a bit harder to write
expectThat(entity) {
get(ResponseEntity<String>::statusCode).isEqualTo(HttpStatus.OK)
get(ResponseEntity<String>::getBody). ??
}
But not as smooth as:
obj.Property.Should().BeEquivalentTo(expected)
in dotnet, where it will report the name obj
and property Property
in the failure message.Pihentagy
06/27/2023, 2:00 PM```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```
Charles Flynn
06/27/2023, 3:55 PMx shouldBe y