Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4075

shouldFailWithCause no longer works for unchecked exceptions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.0
    • 1.7.2, 1.8-beta-1
    • None
    • None

    Description

      So we upgraded from 1.6.3 to Groovy 1.7.0 and realized that one of our tests started failing... it seems that in 1.7.0 unchecked exceptions are simply rethrown (groovy.lang.Closure#throwRuntimeException(Throwable) called from #call(Object[])). Which in groovy.util.GroovyTestCase#shouldFailWithCause(Class,Closure), the exception falls to the catch Throwable branch and the cause is not attempted to be determined beyond that, which causes the test to fail.

      Example test showing a successful checked and unsuccessful unchecked exception:

      package dummy;
      
      import groovy.util.GroovyTestCase;
      
      import java.io.IOException;
      
      import org.junit.Test;
      
      /**
       * Demonstrates cases of should fail with cause.
       * @author Charlie Huggard-Lee 
       */
      class DummyTest extends GroovyTestCase {
          
          public static void failChecked() throws Exception {
              throw new Exception(new IOException());
          }
          
          public static void failUnchecked() {
              throw new RuntimeException(new IOException());
          }
          
          
          @Test
          public void testcheckedFailure() {
              //Hurray!
              shouldFailWithCause(IOException.class, {DummyTest.failChecked()})    
          }
          
          @Test
          public void testuncheckedFailure() {
              //BOO!!!
              shouldFailWithCause(IOException.class, {DummyTest.failUnchecked()})    
          }
          
      }
      

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            achuggardlee Charlie Huggard-Lee
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: