JavaHamcrest
JavaHamcrest copied to clipboard
New BeanHas and BeanProperty matchers
The idea is to be able to test multiple properties in a single assertion and get a decent error message when at least one of them does not match.
I've written these matchers and we use them in a few projects at work. We thought that it would be a good idea to contribute back to JavaHamcrest. I changed my original classes to so it would fit better the coding style used in JavaHamcrest, including the way the tests are written.
I know that Hamcrest has the allOf and hasProperty matchers. They are very good but I personally think that BeanHas and BeanProperty could be a good addition to the library since they work in a slightly different way.
For more details, I've blogged about the matchers here: http://craftedsw.blogspot.co.uk/2012/05/testing-multiple-properties-with-single.html
I'm curious -- what does this add that can't be done by combining multiple hasProperty
into an allOf
?
I think that hasProperty works well when testing a single property. allOf is good for combining different matchers.
Using allOf and multiple hasProperty, in my view, give us a broken readability. Example:
assertThat(myObject, allOf(hasProperty(...), hasProperty(...)))
I think that assertThat(myObject(has(property(..), property(...)) gives a better readability. On top of that, BeanHas and BeanProperty are offering a better error message when the assertion fails.
Hi guys,
Is there anyone looking at the pull requests? It would be great to have some feedback.
Cheers, Sandro
Hey Sandro,
I'm kinda looking at pull requests, although I'm concentrating on getting a release out before taking much new code in.
Oh god, im am looking for that @scarytom @sandromancuso
I'm curious -- what does this add that can't be done by combining multiple hasProperty into an allOf?
compile time safety
@sandromancuso fancy rebasing this from master, as hamcrest-core
and hamcrest-library
have been refactored a lot and also deprecated, so that everything is just in hamcrest
.
Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates
.
Still trying to understand how has permissions to perform a release.