Skip to content

Diff.toString() returns only first comparison result #232

Description

@Boiarshinov

That's my user story:
I have a test for custom xml marshaller in my work project. Test is written in a way similar to XmlUnit user guide. Last line of my test was:

// JUnit 5 assertion
Assertions.assertFalse(diff.hasDifferences(), diff.toString())

After some test sources refactoring test was failed with message that one of xml tag actual values diffs with expected one.
I fixed the expected value in xml sample and was expecting that test will be green this time.
But it wasn't.
It failed with another message about difference in value of another xml tag.

I found a solution in a assertion refactoring:

Assertions.assertFalse(diff.hasDifferences(), diff.differencies.joinToString("\n"))
// `joinToString()` - is a standard Iterable method in Kotlin

With that refactoring I was able to found all differencies simultaneously and fix them in a one try.

But I think that it would be better to return all failed comparison results in Diff.toString() method.
First of all it's a user guide recommendations to write assertions with toString() invocation.
Also this toString() behavior would match Object.toString() javadoc which says

Returns a string representation of the object.

Only one comparison result cannot be full string representation of the object.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions