如何为grails应用程序进行并发修改测试 [英] How to do concurrent modification testing for grails application

查看:137
本文介绍了如何为grails应用程序进行并发修改测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有没有任何插件/工具/机制?我想要运行测试,模拟用户同时修改某些Grails应用程序的某些数据。我可以用它来有效地做到这一点?他们不一定是具体的Grails。应该可以同时触发多个动作。



我宁愿在功能级别上运行测试(到目前为止我使用Selenium进行其他测试)以从用户角度看结果。当然,除了集成测试之外,如果您还建议在集成级别上运行并发修改测试,也可以这样做。

最近我已经使用了Geb(http://grails.org/plugin/geb/)。它是一个位于WebDriver和Selenium之上的层。它非常容易编写Grails脚本作为应用程序中的用户,然后在不同的控制台上运行多个实例。 Geb使用jQuery风格的语法在DOM中定位非常酷的东西:

  import geb.Browser 
import geb.Configuration

includeTargets<< grailsS​​cript(_ GrailsInit)

target(main:尽可能快地做东西){

配置cfg = new配置(baseUrl:http:// localhost :8080 / your_app /)

Browser.drive(cfg){
转到用户/登录
$(#login form)。 b电子邮件=someone@somewhere.com
密码=秘密
_action_Login()。click()
}
...
}
}

setDefaultTarget(main)

只需将脚本放入脚本/ YourScript.groovy,然后你可以做Grails YourScript来运行它。我通过全速运行其中的几个来追踪一些并发问题。您需要制作战争并正确部署,因为在开发模式下Grails非常缓慢,并且很快就会耗尽permgen空间。


I'd like to run tests that simulate users modifying certain data at the same time for a grails application.

Are there any plug-ins / tools / mechanisms I can use to do this efficiently? They don't have to be grails specific. It should be possible to fire multiple actions in parallel.

I'd prefer to run the tests on functional level (so far I'm using Selenium for other tests) to see the results from the user perspective. Of course this can be done in addition to integration testing if you'd recommend to run concurrent modification tests on integration level as well.

解决方案

I have used Geb (http://grails.org/plugin/geb/) for this recently. It is a layer on top of WebDriver and Selenium etc.. Its very easy to write a Grails script to act as a user in your app and then just run several instances on different consoles. Geb uses a jQuery style syntax for locating stuff in the DOM which is very cool:

import geb.Browser
import geb.Configuration

includeTargets << grailsScript("_GrailsInit")

target(main: "Do stuff as fast as possible") {

    Configuration cfg = new Configuration(baseUrl: "http://localhost:8080/your_app/")

    Browser.drive(cfg) {
        go "user/login"
        $("#login form").with {
            email = "someone@somewhere.com"
            password = "secret"
            _action_Login().click()
        }
        ...
    }
}

setDefaultTarget(main)

Just put your script in scripts/YourScript.groovy and then you can do "Grails YourScript" to run it. I tracked down some concurrency issues by just running several of these at full speed. You do need to build a war and deploy it properly as Grails in dev mode is very slow and runs out of permgen space quite quickly.

这篇关于如何为grails应用程序进行并发修改测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆