Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails/groovy testing - any difference between assert and assertEquals methods

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?

like image 439
shuttsy Avatar asked Dec 20 '22 22:12

shuttsy


2 Answers

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.

like image 144
Jeff Storey Avatar answered Dec 22 '22 11:12

Jeff Storey


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.

like image 36
dmahapatro Avatar answered Dec 22 '22 10:12

dmahapatro