-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FEST-Assert like syntax #37
Comments
It sounds like it work well as an add-on library. I'm not sure what the API would look like and how it would support all uses that Hamcrest is put to (e.g. matching parameters of mock objects, defining wait rules for async testing, validation in GUIs, etc.). Why don't you put something together and publish it in a repo so we can see? |
I was thinking about the fluent topic for a while. A clear benefit of FEST's fluents is better auto-completion, the disadvantage is that it's harder to extend. Reimplementing FEST-Assert makes no sense, if you want that, just use FEST. Hamcrest relies on static factory methods, so I did a little prototype. It relies on the existing factory methods, but reduces the nesting of parentheses and simplifies chaining conditions. You can find the code here The API is not complete yet, but I think this will be the general direction. |
The purpose of reimplementing FEST on top of Hamcrest is to allow people to The advantage you and others assert (pun intended) for FEST is at best I like the DSL, very similar to how I was envisaging composition operators Truth looks quite interesting; actually had to upgrade my IDE for it to
|
This probably is just an off-topic, but for me FEST offers more matchers for common use cases (like matchers for strings against regular expressions, which Hamcrest does not have and, according to #36, does not plan to have), plus their assertions on extracted properties of an iterable/array allow saving lots of repetitive work in an another common use case (again, Hamcrest fails to provide a solution in the standard library). For me, FEST is much more than syntactic sugar added. |
I agree that hamcrest should provide more matchers by default. I found some I think that Hamcrest should by default provide all Matchers that can be I have avoided comparing the set of available Matchers in comparisons of
|
Just for the record: I would not say that what I did is a reimplementation of FEST, because of the architectural differences. (For those who don't know FEST: FEST has a deep hierarchy of assert classes and a separate assert method for every value type, which makes it difficult to extend, and uses conditions/matchers only as a workaround for extensions. Hamcrest has a shallow hierarchy of matchers and, just like my fluent DSL, provides only a few variants of the same assert method. You cannot do I agree that the advantage of FEST will disappear as IDEs and the compiler get better at implying generic types, although FEST still has fewer parentheses. Also, for the DSL I introduced the concept of adapters. It would be quite easy to implement a property adapter that reads a value via reflection. Paul, I don't know how far you got with your own implementation and how much time you have, but maybe it would make sense to join our efforts? |
"Hamcrest ... provides only a few variants of the same assert method" Remember that Hamcrest is not only used for writing assert statements. It is used in many other contexts. |
This was no criticism, on the contrary, this difference is the strength of Hamcrest which also reflects in the design of the DSL. |
I'm going to close this issue as "will not implement" because:
When you write it as an extension library, raise an issue with a link to the project so that we can add it to the list of extensions on https://github.com/hamcrest/JavaHamcrest/wiki/Related-Projects |
I have noticed that there are a few people using FEST-Assert instead of Hamcrest. After looking at it a bit it is really just syntactic sugar. Would it make sense to add something similar into Hamcrest so that people can use the syntax they like but still leverage the Matcher implementations. The FEST-Assert Condition class looks like a Matcher to me.
Any thoughts?
The text was updated successfully, but these errors were encountered: