我的目标是为我自己的Grails插件编写测试。采取措施至今:在Grails中没有为插件插件测试注入服务
- 步骤 - 创建单独的Grails应用程序(在本例中,testApp)内 Grails的插件“测试”文件夹
步骤 - 建立一个插件是 内嵌的应用程序 - 在BuildConfig.groovy添加以下行testApp
grails.plugin.location.PluginName = '../../../../PluginName'
的问题是,在单元测试中,服务(从内联插件)不像注册单元测试中的常规应用那样注入。下面是样本测试:如果这个测试是从的Grails应用程序运行和服务是应用程序的一部分
@TestFor(SampleService)
class SampleServiceUnitSpec extends UnitSpec {
def "Sample Test"(){
setup:
def test = 'ok'
when:
test = "changed"
then:
assert service
assert "changed" == test
}
}
服务注入。如果此测试是通过包含服务的内联插件从testApp运行的,则不会注入该服务。如果测试是插件单元测试和插件中声明的服务,则不会注入该服务。
如何注入服务以便测试?任何好的文档,posts.etc关于如何最好的测试Grails插件?谢谢
“在Grails插件的'test'文件夹中创建单独的Grails应用程序(在我们的例子中为testApp) - 你在插件里面创建一个Grails应用程序吗? – dmahapatro
是的。这里是我得出这个结论的来源: – latvian
http://www.slideshare.net/mjhugo/building-grails-plugins-tips-and-tricks – latvian