【问题标题】:UrlMappingsTests - Could not load class in test type 'integration'?UrlMappingsTests - 无法在测试类型“集成”中加载类?
【发布时间】:2023-03-09 06:55:02
【问题描述】:

我正在尝试为我的 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]       

             ^

【问题讨论】:

    标签: grails groovy junit url-mapping


    【解决方案1】:

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

    【讨论】:

    • 我在没有运行的情况下找不到一个类。我正在使用 1.3.7
    • 嗯,好吧,我正在 1.3.6 上测试我的,它正在工作。注释掉后,您可以发布完整的堆栈跟踪吗?
    • 我开始了一个新项目,但在 1.3.7 中失败了。我怀疑这是一种回归。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多