如何在测试视图时模拟 Asset-Pipeline 标签库

How to mock the Asset-Pipeline taglib when testing a view

我有一个测试,其中 gsp 使用资产管道标签 assetPath,在 grails 2 中我没有问题,但在 grails 3 中我得到一个 org.grails.taglib.GrailsTagException: [SOME_GSP.gsp:184] Error executing tag <g:form>: Error evaluating expression [assetPath(src: 'SOME_PDF.pdf')] on line [60]: No signature of method: SOME_GSP_gsp.assetPath() is applicable for argument types: (java.util.LinkedHashMap) values: [[src:SOME_PDF.pdf]]

Grails 3.1.6

示例测试文件:

@TestMixin(GroovyPageUnitTestMixin)
class SomeTests extends Specification {

    void "ssn is not returned to the SOME_GSP page"() {
        given:
        def cmd = new commandObject(SOME_FIELD: 'data')

        when:
        def renderedView = render(view: 'SOME_GSP', model: [cmd: cmd])

        then:
        assert !renderedView.contains('data')
    }
}

结果我需要模拟某些 类:

@Mock([AssetsTagLib, AssetMethodTagLib, AssetProcessorService])

为了让 类 得到解决,我需要向我的 build.gradle

添加一个 testCompile 依赖项
testCompile "com.bertramlabs.plugins:asset-pipeline-grails:2.9.4"