Reputation: 1645
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?
Upvotes: 4
Views: 5538
Reputation: 50245
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.
Upvotes: 2
Reputation: 57192
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.
Upvotes: 9