rajs2020
4 years agoFrequent Contributor
Fluent or English like assertions in Groovy?
In groovy scripts, for assertions, I see that only the assert statement is used. Instead of that, I would like to use English like assertions similar to the ones in these Java testing libraries - TestNg, Junit and Hamcrest etc.
Hamcrest asserts:
assertThat(list, both(hasSize(1)).and(contains(42)));
Groovy asserts:
assert list.size == 1
assert list.contains(42)
This is just a small example, so it might seem like hamcrest is not very different or useful than the simple assert. To see the benefits of hamcrest, see more detailed examples.
Yes it is very much possible, nothing is stopping you to do so.
All you need is to add the respective depencies into READYAPI_HOME/bin/ext directory and restart the tool.
Here is the same example you cited: