Giter Club home page Giter Club logo

Comments (4)

manfred-brands avatar manfred-brands commented on June 2, 2024

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.

waacton avatar waacton commented on June 2, 2024

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.

manfred-brands avatar manfred-brands commented on June 2, 2024

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.

waacton avatar waacton commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.