Grails
  1. Grails
  2. GRAILS-8748

Metaclass not cleaned up when running unit tests in interactive mode

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0 final
    • Fix Version/s: 2.0.1
    • Component/s: Testing
    • Labels:
      None
    • Testcase included:
      yes

      Description

      I have these tests:

      @TestFor(Book)
      class BookTests {
      
          void testMetaClassOnce() {
              assert !Book.metaClass.hasMetaMethod('foo')
      
              Book.metaClass."static".foo = {-> 'bar' }
      
              assert Book.metaClass.hasMetaMethod('foo')
              assert Book.foo() == 'bar'
          }
      
          void testMetaClassTwice() {
              assert !Book.metaClass.hasMetaMethod('foo')
      
              Book.metaClass."static".foo = {-> 'bar' }
      
              assert Book.metaClass.hasMetaMethod('foo')
              assert Book.foo() == 'bar'
          }
      }
      

      When run from the command line, they pass every time. When run from grails interactive mode using "test-app unit:", they both pass the first time but fail the second time. The failure points to the first line of the test, indicating that the meta methods are still present.

      grails> test-app unit:
      | Completed 2 unit tests, 0 failed in 2526ms
      | Tests PASSED - view reports in target/test-reports
      grails> test-app unit:
      | Running 2 unit tests... 1 of 2
      | Failure:  testMetaClassOnce(metaclasstest.BookTests)
      |  Assertion failed: 
      
      assert !Book.metaClass.hasMetaMethod('foo')
             |     |         |
             false |         true
                   groovy.lang.ExpandoMetaClass@241ee2c5[class metaclasstest.Book]
      
      	at metaclasstest.BookTests.testMetaClassOnce(BookTests.groovy:9)
      | Running 2 unit tests... 2 of 2
      | Failure:  testMetaClassTwice(metaclasstest.BookTests)
      |  Assertion failed: 
      
      assert !Book.metaClass.hasMetaMethod('foo')
             |     |         |
             false |         true
                   groovy.lang.ExpandoMetaClass@241ee2c5[class metaclasstest.Book]
      
      	at metaclasstest.BookTests.testMetaClassTwice(BookTests.groovy:18)
      | Completed 2 unit tests, 2 failed in 186ms
      | Tests FAILED  - view reports in target/test-reports
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Matt Sheehan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development