示例TagLib: 我需要嘲笑' params'在某些请求中使用
class MyTagLib {
static namespace = 'p'
format = { attrs -->
def siteId = params.siteId // I need to mock this
def domainLanguage = params.domainLanguage.toString()
.
.
.
}
答案 0 :(得分:0)
您应该首先查看http://grails.github.io/grails-doc/latest/guide/testing.html#unitTestingTagLibraries
在你的情况下,你可能会做类似的事情:
@TestFor(MyTagLib)
class MyTagLibSpec extends Specification {
def "test something with params"() {
given:
params.siteId == "mySiteId"
params.domainLanguage = new DomainLanguage()
when:
def result = tagLib.format(attr1: 'someAtribute').toString()
then:
result == 'expectedOutput'
}
}
但我会首先尝试阅读文档: - )