加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

单元测试grails标签

发布时间:2020-12-14 16:20:41 所属栏目:大数据 来源:网络整理
导读:我写了一个Grails标签,它只是围绕 Grails select tag的一个非常薄的包装器 package com.exampleclass MyTagLib { def listTrees = {attrs - ListTreeDto allTrees = getMandatoryAttributeValue(attrs,'trees') out g.select(from: allTrees) }} 我已经为这
我写了一个Grails标签,它只是围绕 Grails select tag的一个非常薄的包装器

package com.example

class MyTagLib {
  def listTrees = {attrs ->
    List<TreeDto> allTrees = getMandatoryAttributeValue(attrs,'trees')
    out << g.select(from: allTrees)
  }
}

我已经为这个类进行了单元测试,但是当我运行它时,在执行最后一行时出现以下错误:

groovy.lang.MissingMethodException: No
signature of method:
com.example.MyTagLib.select() is
applicable for argument types:
(java.util.LinkedHashMap)

在运行单元测试时,似乎无法使用g命名空间中的grails标记引用.我尝试过创建集成测试,但这也不起作用.

有没有办法测试一个调用另一个标签的标签,而无需对其他标签的输出进行存根/模拟?

解决方法

你必须模拟你正在使用的grails taglib并通过metaClass机制注入它.

protected void setUp() {
    super.setUp()
    mockTagLib(FormTagLib)
    def g = new FormTagLib()
    tagLib.metaClass.g = g
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读