Custom string format for collection members?

11 views
Skip to first unread message

Oskar Berggren

unread,
Jan 26, 2012, 6:38:33 AM1/26/12
to NUnit-Discuss
Hi,

I have a collection of objects that I test together with
Has.Member().Using(custom comparison). When the element isn't found,
nunit prints a string representation of the actual collection.
However, because the objects in the collection doesn't override
ToString(), this printout is rather meaningless.

Overriding ToString() for this type is not possible.

Is it possible to specify a custom "object formatter/renderer" that
NUnit will use to get a string representation of each collection
member?

/Oskar

Charlie Poole

unread,
Feb 6, 2012, 6:19:42 PM2/6/12
to nunit-...@googlegroups.com
Hi Oskar,

You can provide a custom constraint, which combines a custom comparison
with the sort of renderer you are looking for. To use it, you could write
something like Has.Member.Matches(new MyConstraint(<args>))

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>

Reply all
Reply to author
Forward
0 new messages