I'm using NUnit 2.6.2 + Fluent Assertions 2.0.1.
I want to assert that two references do NOT point to the same object instance. I can't find a clean way to express that.
NUnit has Assert.ReferenceEquals(ref1, ref2)
- but I can't find the negated assertion.
In Fluent Assertions I can't find anything to directly support this scenario.
The only way I could do it was like this:
NUnit: Assert.False(object.ReferenceEquals(ref1, ref2));
Fluent: object.ReferenceEquals(ref1, ref2).Should().BeFalse();
Both of these seem less than ideal in terms of minimal noise. Is there a better way?
Fluent Assertions are important in unit testing because they allow the code to be easily read and followed. This makes it easier to determine whether or not an assertion is being met. As a result, everyone can easier read and understand unit tests, making it easier to locate the failing assert.
Just install ExpectedObjects from Nuget, you can easily compare two objects's property value, each object value of collection, two composed object's value and partial compare property value by anonymous type. Reference: ExpectedObjects github. Introduction of ExpectedObjects.
Fluent Assertions is a set of . NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit test.
NUnit Assert class is used to determine whether a particular test method gives expected result or not. In a test method, we write code the check the business object behavior. That business object returns a result. In Assert method we match the actual result with our expected result.
You can use NotBeSameAs() method:
ref1.Should().NotBeSameAs(ref2);
Its documentation says:
Asserts that an object reference refers to a different object than another object reference refers to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With