我有一个模板gsp,它使用<g:set var="test" bean="testService">
来访问标题中的服务。
当我尝试通过@TestMixin(GroovyPageUnitTestMixin)
对模板进行单元测试时,如何模拟/设置此服务?
测试类似于:
def renderedView = render(template: '/templates/test')
assert renderedView.contains("test text")
运行测试时,我得到: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException:执行标记时出错:没有定义名为'testService'的bean 在
C__Users_some_name_intellij_project_grails_app_views_templates__test_gsp.run(C__Users_some_name_intellij_project_grails_app_views_templates__test_gsp:24)
at grails.test.mixin.web.GroovyPageUnitTestMixin.renderTemplateToStringWriter(GroovyPageUnitTestMixin.groovy:166)
at grails.test.mixin.web.GroovyPageUnitTestMixin.render(GroovyPageUnitTestMixin.groovy:134)
at project.view.TestTests.myTest(TestTests.groovy:22)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'testService' is defined
... 4 more