UrlMappingsTests - Could not load class in test type 'integration'?

1.3k Views Asked by At

I'm trying to create a UrlMappingsTest for my grails project, and I'm getting the following exception:

java.lang.RuntimeException: Could not load class in test type 'integration'
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:391)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)

My class is pretty simple, and I tried to follow the example. What's going on?

import grails.test.GrailsUrlMappingsTestCase

class UrlMappingTests extends GrailsUrlMappingsTestCase {
//  static mappings = UrlMappings

  void testForwardingUrls(){
    assertForwardUrlMapping( "/rest/users/stefan/files", controller: "file", action: "allFiles" );
  }
}

With the static line uncommented, I get

  [groovyc] You attempted to reference a variable in the binding or an instance variable from a static context.
  [groovyc] You misspelled a classname or statically imported field. Please check the spelling.
  [groovyc] You attempted to use a method 'UrlMappings' but left out brackets in a place not allowed by the grammar.
  [groovyc]  @ line 7, column 21.
  [groovyc]      static mappings = UrlMappings
  [groovyc]       

             ^
2

There are 2 best solutions below

0
On BEST ANSWER

I've logged a ticket on the grails bugtracker for this.

3
On

If you look at the source for GrailsUrlMappingsTestCase you'll see that (as you maybe suspect) static mappings = UrlMappings isn't needed, since it does that by default if you don't specify a static mappings variable. Do you get a nested exception under the java.lang.RuntimeException: Could not load class in test type 'integration' when you leave the line commented out? Post the full stacktrace, it should work. What version of grails are you using?