Results 1 to 2 of 2

Thread: Turning off Assertions

  1. #1
    Join Date
    Jun 2011
    Location
    San Francisco
    Posts
    1

    Default 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.

    Richard

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •