禁用 Grails 插件
在我的 Grails 应用程序中,我想在运行单元测试时阻止加载 Searchable 插件。 我尝试在 Bootstrap 类中使用以下代码执行此操作
def grailsApplication
def init = {servletContext ->
def currentEnv = grails.util.Environment.current.name
if (currentEnv == 'test') {
def doNothing = {println "Searchable is disabled"}
// This returns null!
def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")
searchablePluginClass.metaClass.doWithDynamicMethods = doNothing
searchablePluginClass.metaClass.doWithSpring = doNothing
searchablePluginClass.metaClass.doWithApplicationContext = doNothing
}
}
但这不起作用,因为 grailsApplication.getClassForName("SearchableGrailsPlugin")
返回 null,大概是因为当此代码时此类不在类路径上运行。 还有其他方法可以禁用此插件吗?
In my Grails app, I want to prevent the Searchable plugin from loading when running my unit tests. I tried doing this using the following code in the Bootstrap class
def grailsApplication
def init = {servletContext ->
def currentEnv = grails.util.Environment.current.name
if (currentEnv == 'test') {
def doNothing = {println "Searchable is disabled"}
// This returns null!
def searchablePluginClass = grailsApplication.getClassForName("SearchableGrailsPlugin")
searchablePluginClass.metaClass.doWithDynamicMethods = doNothing
searchablePluginClass.metaClass.doWithSpring = doNothing
searchablePluginClass.metaClass.doWithApplicationContext = doNothing
}
}
However this doesn't work because grailsApplication.getClassForName("SearchableGrailsPlugin")
returns null, presumably because this class isn't on the classpath when this code runs. Is there any other way that I can disable this plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道如何禁用该插件,可能有一种方法 本机指南针 XML
使用 grails,您可以通过以下方式使单元测试更容易忍受...
安装这个附加插件:
grails install-searchable-config
这将为您提供一个 grails-app/conf/Searchable.groovy 文件。 您可以编辑
environments.test.searchable 闭包至少禁用bulkIndexOnStartup 和mirrorChanges。
I am not sure how to disable the plugin, there might be a way with native compass XML
With grails you might be able to make unit testing more bearable with the following...
Install this additional plugin:
grails install-searchable-config
This will give you a grails-app/conf/Searchable.groovy file. You can edit
environments.test.searchable closure to at least disable bulkIndexOnStartup and mirrorChanges.
要禁用运行测试所使用的测试构建的插件 - 如果您在 BuildConfig.groovy 中包含插件,则可以在其中执行以下操作;
这会阻止构建环境在测试时包含该插件,但是,如果您使用此环境构建 UAT 版本,这也会影响测试版本。
To disable a plugin for the test build, which running tests uses - the following is possible in the BuildConfig.groovy if you include your plugin there;
This stops the build environment from including the plugin when testing, however, this WILL also effect a test release if you use this environment to build UAT releases.
我找到了解决方案。 将以下内容添加到 Config.groovy:
I found a solution. Add the following to Config.groovy: