MarkusAmshove / Kluent

Fluent Assertion-Library for Kotlin
https://markusamshove.github.io/Kluent/
MIT License
867 stars 64 forks source link

Improve errors #193

Closed igorwojda closed 3 years ago

igorwojda commented 3 years ago

While testing complex models it's quite hard to say where the problem lies exactly (which model property does not match expected value):

Now:

java.lang.AssertionError: 
The following assertion failed:
Expected <[Album(name=albumName, artist=artistName, wiki=AlbumWiki(published=published), mbId=1)]>, actual <[Album(name=albumName, artist=artistName, wiki=null, mbId=1)]>.

If two object are of the same type we could try to display each property in separate line (maybe even add tabs for nested models/properties). Goal here is to instantly know which property does not have expected value:

Expected

java.lang.AssertionError: 
The following assertion failed:
Expected:
name=albumName - OK
artist=artistName - OK
wiki=null but it was AlbumWiki(published=published, summary=summary)
MarkusAmshove commented 3 years ago

Did you use shouldBe or shouldEqual?

You can try shouldBeEquivalentTo as it might have the formatting you need.

We could also try to reuse the formatting for Objects that are not found to be equal with shouldBe or shouldEqual

igorwojda commented 3 years ago

Tried shouldBeEquivalentTo, but:

image

🤔

drcolombo commented 3 years ago

shouldBeEquivalentTo doesn't support backtick notation, only pure JVM, as it expects 2 parameters, not only one: an expected object and config of EquivalencyAssertionOptions type. In other words, this should work fine: result.shouldBeEquivalentTo(albums)

drcolombo commented 3 years ago

If my suggestion works, then @MarkusAmshove , could you please close the issue?

MarkusAmshove commented 3 years ago

I'll interpret igors emoji reaction as "case closed" :-)