Jun 30th, 2011, 03:39 PM
Turning off Assertions
We'd like to use Grails/Groovy assertions in the same way as we can with Java ones, so we can turn on during QA and turn off in production. It appears that Groovy assertions cannot be turned off.
It this true? If so, can it be changed? I understand about pre and post conditions etc, but I think that not being able to turn off assertions robs them of one of their main uses:to instrument code to trap bugs during testing. You wan to be able to assert complicated checks for testing, but not pay that overhead in production.
Any hints would be gratefully received.
Jul 8th, 2011, 09:48 AM
This doesn't seem possible, sorry. I suggest you raise an issue or discuss it on the Groovy User mailing list (or do both). The workaround is to add your own guards that only execute assertions if they are enabled (which may be based on a system property or something else). An AST transformation could make this cleaner, but that's quite a high-tech solution. Raising the issue on the Groovy User mailing list may result in more concrete suggestions.