I have numerous Grails unit and integration groovy test classes.
Originally I used methods such as assertEquals, assertNull, assertTrue, assertFalse, etc.
assertEquals 0, User.list().size()
but recently I've been preferring to use a straight assert:
assert User.list().size() == 0
Is there any difference between these 2 approaches?
The assertEquals
is using a JUnit assertion, whereas the assert
is using groovy's power assert. The power assert gives you much nicer error messages and is built-in to the language. You should generally use that one when you can.
An AssertionError
is thrown in case assertEquals
fails but no such error is thrown in case when assert
is used but it does a power assert in groovy and provides good assertion messages when fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With