I use FluentAssertions for all of my asserting needs. I like it’s API better than the assert methods you get with the .Net framework, and the FluentAssertions library provides an overall more fully featured set of assertion options. It’s open-source and continually updated, too, which makes it all right in my book. Sometimes, though, while I’m furiously writing tests, I get this test failure signature and it catches me off guard.
Subject has property Subject that the other object does not have.
Here’s a sample NUnit test case that would cause this particular error.
internal class MistakesTests { [Test] public void ThisDumbThingIKeepDoing() { var thing = new Thing { FirstName = "Nelson" }; var thing2 = new Thing { FirstName = "Nelson" }; // This should definitely pass, right? thing.Should().ShouldBeEquivalentTo(thing2); } private class Thing { public string FirstName { get; set; } } }
As you can see, I’m just doing a very simple object graph comparison, but it isn’t working as I intended. Can you spot the error?
Whereas I should be calling ShouldBeEquivalentTo on my Thing instance, I’m actually calling it on an instance of ObjectAssertions type from the FluentAssertions library. Whoops! ?
Life saver!
Tisk tisk. Wher is that wall of shame?
Thank you,
I had the same problem, you saved me ?
I was scratching my head over this, as I had something like
expected.Should().NotBeNull().And.ShouldBeEquivalentTo(actual);
Thank you!
Thanks !
Good man!!! Saved me as well – what a terrible error message.
I feel so dumb right now. Thanks ?
Thanks – just happened to me ?
Silly mistake but apparently a lot of people have made it! Thanks for pointing me in the right direction.
+1 Thank you ?
What everyone else has said – it certainly had me scratching my head for 5 minutes.
+1 your, -1 for this silly error message
3 years later, I just did the same thing. First google result, you rule. Thanks!
Saved me!
I’m another victim! Chers
Perhaps it is an idea for some of you to create a pull request with a better error message, instead of giving the author of this fabulous library minus ones.
amazing! saved me after wasting an hour