0

鉴于此映射:

"/student/degree/$studentid/$degreecode"(controller:'student', action:'degree')

我正在尝试下面的测试,但都失败了,AssertionFailedError: '...did not match any mapping'而且都是有效的有效 URL。我可以使用仅“/student/degree”的测试 URL 成功,我认为由于需要参数而应该失败。

似乎这些assertURL方法没有处理多个参数。这是否仅适用于“id”并且无法为这些 URL 创建测试?

@TestFor(UrlMappings)
@Mock([StudentController])
class UrlMappingsTests {
    void testUrlMappings() {
        assertForwardUrlMapping("/student/degree/102345678/N", controller: "student", action: "degree") {
            assertForwardUrlMapping("/student/degree/102345678/N", controller: "student", action: "degree") {
                studentid = 102345678
                degreecode = "N"
            }
        }
    }
}
4

1 回答 1

1

用 Grails 2.2.4 测试,它对我有用,我只是添加了一个自定义映射类:

package test

class MyUrlMappings {
  static mappings = {
    "/test/show/$myId/$myVal"(controller: "test", action: "show")
  }
}

import spock.lang.*
import test.MyUrlMappings

@TestFor(MyUrlMappings)
@Mock([TestController])
//I'm using Spock
class MyUrlMappingsSpec extends Specification {

  void "mapping should consider myId and myVal"() {
    expect:
      assertForwardUrlMapping("/test/show/1/tst", controller: "test", action: "show") {
        //all params considered as String
        myId = '1'
        myVal = 'tst'
      }
  }

}
于 2013-10-09T16:28:36.757 回答