Comments (4)
NUnit 3 only used reference comparison and regardless of the parameter passed to the Thing constructor, even if both are the same, the instances would compare as not equal.
Version 4 introduced a Property comparer which compares the values of properties. in your case Number, which in all cases is the same and the two instances are considered equal as the values of all properties are the same
You have both a property and a public field, if you change the latter to a property, the test will succeed.
Although we could compare fields, one issue already mentions that those should not be compared as the might be implementation details. Maybe we could only compare public (read-only) fields. However MS actively promotes to use properties for value classes. See CA1051
from nunit.
Thanks for the quick clarification.
In my actual use case I have a some public properties and an internal field (in my reproduction I was guessing it was the internal that was part of the issue). It looks like changing the internal field to an internal property is not enough, the test only passes when it is a public property?
from nunit.
Yes it only tests public properties as internal ones could be implementation details.
Look at it like this, a user of your class has only access to the public ones, if the comparison says, instances are different, it has no idea why as all properties the user can see are the same.
Before NUnit4, users had to test each property separately to see if any of them was different. They cannot do that if those properties are not public.
If you want complete control over what is considered Equal and what not, you must implement IEquality<T>
on your class.
from nunit.
Aye that makes sense.
I was using it to test my understanding of the inner workings of my library as opposed to how it might be consumed by a user, which now sounds like a little bit of unfair repurposing 😅. Easily dealt with now that I know what's changed, thanks.
from nunit.
Related Issues (20)
- Increment StreamsComparer by 'Actual bytes read' rather than the buffer size
- Some release note between NUnit 2.6.4 and 3.14.0 should state the breaking change related to Trace and Debug output HOT 4
- Provide a ProgressTraceListener to redirect Trace output to the NUnit Progress output HOT 1
- Value equality on subset of object properties HOT 3
- Difference between net5.0/net6.0 and netframework 4.7.2 in test tear down HOT 5
- Either enable partial TestCaseSource combinatorial with Values, or document this is a limitation of TestCaseSource HOT 1
- Re-add "legacy" Assert methods HOT 7
- Constraint helper classes modification request HOT 3
- State that the scope of a `SetUpFixture` is limited to an assembly HOT 2
- Possibilities to estimate the total test duration before starting the first test? HOT 13
- Provide a way to ignore a failed assertion HOT 14
- The dll's in the release 4.1 has version 4.0.1
- Missing possibility to retrieve a test's resulting `ParallelScope` HOT 1
- Improve PropertiesComparer diagnostics HOT 1
- Unexpected GreaterThan(NaN) behavior HOT 2
- AssemblySelectLimit does not work HOT 1
- Is.EqualTo stopped working after upgrade from 4.0.1 to 4.1.0 HOT 3
- Provide generic type definitions for `TestCaseData` to make it type safe. HOT 2
- Stacktrace calls lost on exception of type TargetInvocationException HOT 2
- Sections in Assert.Multiple HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nunit.