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?

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.

1

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.