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?

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

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.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest