Skip to content

Print expected and actual values on different lines for lists #570

@VirtualParticle

Description

@VirtualParticle

When asserting on lists of objects with very long string representations, it can be quite difficult to see what differs between the actual and expected values.

assertThat(someList).containsExample(a, bunch, of, big, objects)

If there's an error, this will print out something like

expected to contain exactly:<[ReallyBigObject(a=0,b=1,c=2...), ReallyBigObject(a=3,b=4,c=5...)]> but was:<[ReallyBigObject(a=0,b=1,c=2...), ReallyBigObject(a=2,b=4,c=5...)]>

I usually end up copying and pasting the two values and putting them on separate lines or using the IDE's compare feature to see the difference. It'd be much easier to compare them visually if they were printed on separate lines:

expected to contain exactly:
[ReallyBigObject(a=0,b=1,c=2...), ReallyBigObject(a=3,b=4,c=5...)]
but was:
[ReallyBigObject(a=0,b=1,c=2...), ReallyBigObject(a=2,b=4,c=5...)]

One way to get around this is to sidestep the list assertion altogether and just compare each item individually but that's sort of annoying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions