This project is read-only.

A more descriptive error message for Likeness

May 24, 2011 at 5:32 AM

Let me begin by saying that I am using both Likeness and Autofixture and I absolutely love both.

I was wondering if there is a way to make the likeness error message to something more descriptive.

I am currently getting something of the sort:

{"  Expected: <Likeness of .DomainModel.Entities.MyExampleClass>\r\n  But was:  <.DomainModel.Entities.MyExampleClass>\r\n"}

and the only way I can figure out what property is failing is to comment out my custom .With for OmitAutoComparison until the assert passes.

That seems rather tedious. Is there a way to get likeness to tell me exactly which property doesn't pass the comparison criteria?




May 24, 2011 at 6:40 AM

Assuming that you are getting the above message from some sort of test assertion, there's not a whole lot which can be done to address that particular scenario, since all assertions (that I know of) are implemented as a sequence of Equals followed by a ToString when the result of Equals fails. To enable a better exception message from an Assert.Equal method call would require that Likeness.ToString should know against which object it was previously compared. However, both ToString and Equals are supposed to be stateless, non-mutating methods so there's no elegant way to address exactly that scenario.

However, Likeness has a ShouldEqual assertion method that provides what you ask for as an atomic operation:


This will throw a descriptive exception whenever the comparison fails.


May 24, 2011 at 4:14 PM

You assumptions were spot on. Thanks a lot for the thorough explanation. I will try your suggestion.

May 24, 2011 at 7:55 PM

Sounds good. Please let me know if this appropriately addresses the issue, so that I can close it.

Otherwise, please let me know if there's anything else you need.

May 24, 2011 at 7:56 PM

i will test it this afternoon and let you know. thanks for the follow up.

May 25, 2011 at 2:08 AM

It worked! I had to update to version 2.1, but the assertion worked just as described. Thanks a lot for a great time saver feature.