0

我正在尝试为我的 grails 项目创建 UrlMappingsTest,但出现以下异常:

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)

我的课很简单,我试着照着做。这是怎么回事?

import grails.test.GrailsUrlMappingsTestCase

class UrlMappingTests extends GrailsUrlMappingsTestCase {
//  static mappings = UrlMappings

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

在未注释静态行的情况下,我得到

  [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]       

             ^
4

2 回答 2

0

如果您查看源代码GrailsUrlMappingsTestCase您会发现(您可能会怀疑)static mappings = UrlMappings不需要,因为如果您不指定静态映射变量,默认情况下它会这样做。java.lang.RuntimeException: Could not load class in test type 'integration'当您将行注释掉时,您是否得到嵌套异常?发布完整的堆栈跟踪,它应该可以工作。你用的是什么版本的grails?

于 2011-03-01T23:53:39.440 回答
0

我已经为此在grails bugtracker上记录了一张票。

于 2011-03-04T17:47:26.270 回答