willowtreeapps / assertk

assertions for kotlin inspired by assertj
MIT License
771 stars 87 forks source link

Add custom information to an assertion error message. #344

Closed evant closed 3 years ago

evant commented 3 years ago

This came up as a response to https://github.com/willowtreeapps/assertk/issues/12. It would be useful to add additional information to a failure to aid with tracking down the cause. Some bikeshed syntax (may change):

assertThat(success, context = { "DB state: " + repository.findUser(USER_ID) }).hasSize(1)

// expected [size]:<1> but was:<0>
//   DB state: User { name = "Tim" }"