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
assertEquals doesn't work for sets #2296
Comments
As a workaround you can define the expected as
|
I implemented a fix but couldn't create a pull request, so here it is: add the following code in method
|
@mchintoanu - what is the issue you are facing in raising a PR? |
lack of permissions |
@mchintoanu - There should not be any permission constraints. All you need to do is, fork this repository (which will create a Xerox copy of this repo in your account), clone the forked repo to your local machine, apply the changes, push the changes to your repo and then raise a pull request. See here for some good explanation. |
@mchintoanu - You are using an instance of LinkedHashSet, which means you are expecting that order should be maintained.
final Collection<Integer> oneSet = new HashSet<>();
oneSet.add(1);
oneSet.add(2);
final Collection<Integer> anotherSet = new HashSet<>();
anotherSet.add(2);
anotherSet.add(1);
Assert.assertTrue(oneSet.equals(anotherSet)); //passes
Assert.assertEquals(oneSet, anotherSet); //passes |
@amitbhoraniya |
Yes I agree with you, but I don't think for your issue we should change the implementation of |
I believe the contract of assertEquals is broken as long as it doesn't return the same result as equals. And I have just thought of a simpler, cleaner solution than the one I proposed initially:
I'll check out the project and try to create a pull request if I have some spare time in the following days. |
TestNG Version
7.1.0
Expected behavior
assertEquals
yields true if called with two sets that contain the same elements, even if they are defined asCollection
.Actual behavior
Depending on the type of set and the type of objects they contain
assertEquals
might work well or fail because it relies on iterators to compare the two sets and in the case of sets the iteration order is not guaranteed. This behavior is is most evident onLinkedHashSet
s but also appears onHashSet
s depending on the type of objects they contain. I suspect it works well withTreeSet
s, which have a predictable iteration order.Is the issue reproductible on runner?
Test case sample
Test case excerpt (full test in attachment):
AssertEqualsOnSetsTest.zip
The text was updated successfully, but these errors were encountered: