invoking GORM methods from Geb tests

自作多情 提交于 2019-12-20 04:39:08

问题


In my Grails app, I have a suite of Geb tests wherein I invoke various GORM methods to save/retrieve data. This was working fine, until very recently. But now, whenever I try to invoke a GORM method from a Geb test, I get the following error:

Method on class [com.example.MyDomainClass] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.

I'm aware of the fact that under certain circumstances you need to use the remote control plugin to use GORM methods in Geb tests. However, in my case, I run the tests via grails test-app functional and I don't have any JVM forking configured in Config.groovy. In other words, the tests should be running in the same JVM as the app being tested, so I should be able to use GORM methods without the remote control plugin.

I'm using Grails 2.3.11 and Geb 0.10.0.


回答1:


You really should always use grails remote control plugin. You should not depend on the fact that your tests and the application under test run in the same JVM and that you are able to call grails code from your test. This approach will only work under certain circumstances while using the remote control plugin for this will work always.

Even if your tests and app are running in the same JVM (as most probably is still the case for you) some methods, like GORM for example, might be restricted by grails to be only called from a context of a request, because they need that context to be able to work correctly.



来源:https://stackoverflow.com/questions/28505134/invoking-gorm-methods-from-geb-tests

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!