Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Boiarshinov opened this issue Oct 2, 2021 · 4 comments
Closed

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

Boiarshinov opened this issue Oct 2, 2021 · 4 comments

Comments

@Boiarshinov
Copy link
Contributor

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.

@Boiarshinov
Copy link
Contributor Author

XmlUnit Enhancement Proposal: #233

@bodewig
Copy link
Member

bodewig commented Oct 3, 2021

Thank you @Boiarshinov

I don't think changing toString's implementation is the way to go, rather I'd add a new method - which needs to accept a ComparisonFormatter as well. I a way toString's current behavior is a contract provided by XMLUnit that we should not break.

@Boiarshinov
Copy link
Contributor Author

I separate my initial PR to two new:

I tried to drop commits with cosmetic changes from initial PR and refactor it, but I failed, sorry.

@bodewig What do you think about new fullDescription() method?

@bodewig
Copy link
Member

bodewig commented Oct 4, 2021

I liked your #235 approached better and merged that. Many thanks.

@bodewig bodewig closed this as completed Oct 4, 2021
@bodewig bodewig added this to the 2.8.3 milestone Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants