-
Notifications
You must be signed in to change notification settings - Fork 759
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
Assert.Equal
for JValue
with mismatching types asserts to true.
#2713
Comments
Assert.Equal
for JValue
with mismatching types asserts to true/Assert.Equal
for JValue
with mismatching types asserts to true.
This is because
The actual fix here would be for JSON.NET to implement one of the many equality/comparability interfaces provided in .NET. We currently look for and support:
(1) We support both the We are not planning to add special-cased support for JSON.NET, as we don't special case anything that isn't part of the core framework itself. Third party libraries are expected to either conform to the comparison systems provided by .NET, or the testers are expected to use their own custom logic when the third party libraries aren't written to comply, as is the case with JSON.NET. |
@bradwilson please check out the linked SO question.
Totally agree with this. |
Hmm, I think if I changed the behavior, it would be to propagate the exception. Assuming "exception" means "not equal" isn't correct, IMO, because what if you were using Assert.NotEqual? Any exception would cause the code to unnecessarily pass. I want to review this since I'm already catching it, and I assume I had a good reason for it. 😄 |
The commit that changed this is more than 6 years old: xunit/assert.xunit@6349e0c This is the associated PR: xunit/assert.xunit#13 No reasoning there. Maybe @hughbe will remember? $10 says it was added for JSON.NET. 😂 |
Still poking around here, and I've determined that with the 2.5.0 assertion library, So even removing the try/catch would have no impact any more. |
@bradwilson thank you!
Yes, I agree that this is also not the clearest/cleanest solution (though an argument can be made here - if two things can't be compared they are definitely not equal 😊). |
Not sure that this is worth fixing or not, and maybe it is actually will work in the next release (as I can see there is some refactoring going on) but consider the following (from SO question, some explanation for 2.4.2 xunit version there):
Repro:
Expected:
Fail
Actual:
Passes
Workaround
Use
Assert.StrictEqual
(works correctly forJValue
s) or more generic approach -Assert.True(JToken.DeepEquals(jvRight, jvLeft));
.The text was updated successfully, but these errors were encountered: