Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Assert.That

28 views
Skip to first unread message

Andrew Ochsner

unread,
May 17, 2012, 3:53:07 PM5/17/12
to mbun...@googlegroups.com
Very happy to see and use the Assert.That syntax but the NHamcrest matchers seem a bit limited and there hasn't been much in the way of development it seems.  Meanwhile NUnit seems to have a much more robust set of matchers/constraints ( http://nunit.org/index.php?p=constraintModel&r=2.6 ).  Are there any plans to either change the approach or develop more matchers to donate to NHamcrest (something I've been trying to work on in my spare time)?

Thanks

Graham Hay

unread,
May 19, 2012, 12:16:46 PM5/19/12
to mbun...@googlegroups.com
Pull requests will be gratefully received :)

Which matchers do you think would be useful?

The motivation for using the Hamcrest matchers, rather than the NUnit ones, was that all the existing body of knowledge around the Java version (and others) would still be relevant. Whether that was a good idea remains to be seen.

On 17 May 2012 20:53, Andrew Ochsner <aoch...@cs.stanford.edu> wrote:
Very happy to see and use the Assert.That syntax but the NHamcrest matchers seem a bit limited and there hasn't been much in the way of development it seems.  Meanwhile NUnit seems to have a much more robust set of matchers/constraints ( http://nunit.org/index.php?p=constraintModel&r=2.6 ).  Are there any plans to either change the approach or develop more matchers to donate to NHamcrest (something I've been trying to work on in my spare time)?

Thanks

--
You received this message because you are subscribed to the Google Groups "MbUnit.Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mbunitdev/-/j2VM-hG279gJ.
To post to this group, send email to mbun...@googlegroups.com.
To unsubscribe from this group, send email to mbunitdev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mbunitdev?hl=en.

Andrew Ochsner

unread,
May 21, 2012, 11:09:55 AM5/21/12
to mbun...@googlegroups.com
On Saturday, May 19, 2012 11:16:46 AM UTC-5, Graham Hay wrote:
Pull requests will be gratefully received :)

Yep, and I've forked in hopes of adding to it.  Thinking the Property constraints could be useful (also in the Hamcrest library).
 

Which matchers do you think would be useful?

What I find myself struggling with most is collection comparison.  What I really want is something LINQ-like.  Maybe pass a lambda or something to decide whether I have an item in the collection that I was expecting.  Since the objects can be very complex or might not override Equals, I want to be able to do something like Assert.That(collection, Has.Item.Where(x => x.Property == "expected").  (NUnit doesn't really seem to have this either, but I do like their fluent style syntax with modifiers... for example, Is.Not.GreaterThan(3) is a bit easier than Is.Not(Is.GreaterThan(3)) or adding an IgnoreCase modifier to string comparisons...).  That make any sense?  Or is there an easier way to accomplish this?
 

The motivation for using the Hamcrest matchers, rather than the NUnit ones, was that all the existing body of knowledge around the Java version (and others) would still be relevant. Whether that was a good idea remains to be seen.

I think that still holds true.  FWIW, looks like Hamcrest is moving to GitHub as well.  Might want to add NHamcrest under the https://github.com/hamcrest umbrella?
 

On 17 May 2012 20:53, Andrew Ochsner wrote:
Very happy to see and use the Assert.That syntax but the NHamcrest matchers seem a bit limited and there hasn't been much in the way of development it seems.  Meanwhile NUnit seems to have a much more robust set of matchers/constraints ( http://nunit.org/index.php?p=constraintModel&r=2.6 ).  Are there any plans to either change the approach or develop more matchers to donate to NHamcrest (something I've been trying to work on in my spare time)?

Thanks

--
You received this message because you are subscribed to the Google Groups "MbUnit.Dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mbunitdev/-/j2VM-hG279gJ.
To post to this group, send email to mbun...@googlegroups.com.
To unsubscribe from this group, send email to mbunitdev+unsubscribe@googlegroups.com.

Andrew Stopford

unread,
May 21, 2012, 12:56:09 PM5/21/12
to mbun...@googlegroups.com
Hi,

If you want Linq based assert expressions then have a look at AssertEx.That


Andy

To view this discussion on the web visit https://groups.google.com/d/msg/mbunitdev/-/Xaa7kNijjz8J.

To post to this group, send email to mbun...@googlegroups.com.
To unsubscribe from this group, send email to mbunitdev+...@googlegroups.com.

Andrew Ochsner

unread,
May 21, 2012, 2:55:45 PM5/21/12
to mbun...@googlegroups.com
Thanks! I'll give that a play.

Graham Hay

unread,
May 23, 2012, 9:40:38 AM5/23/12
to mbun...@googlegroups.com
What are Property constraints? I thought I'd implemented everything from the java version.

Collection matchers would be nice. I like the linq syntax. It might be easier to implement them in MbUnit, as you could re-use the existing collection asserts (although if you did it in nhamcrest everyone would benefit).

You're definitely right about the syntax, some of it is fugly. Feel free to improve it :)

I hadn't heard they were moving to github. There was a distinct lack of interest last time I posted on their mailing list, but I'll try again.

To view this discussion on the web visit https://groups.google.com/d/msg/mbunitdev/-/Xaa7kNijjz8J.

To post to this group, send email to mbun...@googlegroups.com.
To unsubscribe from this group, send email to mbunitdev+...@googlegroups.com.

Andrew Ochsner

unread,
May 23, 2012, 10:26:17 AM5/23/12
to mbun...@googlegroups.com
Property constraints - this is what they are in NUnit  http://nunit.org/index.php?p=propertyConstraint&r=2.6  and in Hamcrest  https://github.com/hamcrest/JavaHamcrest/tree/master/hamcrest-library/src/main/java/org/hamcrest/beans 

I don't use them a lot but really just to test if an object has a particular property and optionally if it's value is equal to something expected...

I might be mistaken, but looks like we could just port over the matchers from hamcrest-library:
[hamcrest-library.jar]
   The ever-growing library of Matcher implementations. This
   will grow between releases.


I think I might have some time coming up in the next two weeks to take a shot at improving it and have you review it, if that makes sense.

Graham Hay

unread,
May 24, 2012, 4:26:28 AM5/24/12
to mbun...@googlegroups.com
Hmm, I must have just done the ones in hamcrest-core. Sounds good, let me know if I can help in any way.
Reply all
Reply to author
Forward
0 new messages