Grails 1.3.3:controller.redirectArgs.action 未填充
有谁知道最新版本的 Grails (1.3.3) 中的controller.redirectArgs.action 发生了什么?以前可以正常使用,但现在使用时出现 NPE。
class FooController {
def someRedirect = {
redirect(action:"bar")
}
}
class FooControllerTests extends grails.test.ControllerUnitTestCase {
void testSomeRedirect() {
controller.someRedirect()
assertEquals "bar", controller.redirectArgs.action
}
}
在这种情况下,controller.redirectArgs 已经为空......
Does anyone knows what happened to controller.redirectArgs.action in the latest version of Grails (1.3.3)? It used to work properly but now I get NPE when I use it.
class FooController {
def someRedirect = {
redirect(action:"bar")
}
}
class FooControllerTests extends grails.test.ControllerUnitTestCase {
void testSomeRedirect() {
controller.someRedirect()
assertEquals "bar", controller.redirectArgs.action
}
}
In this case controller.redirectArgs is already null...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在将操作与字符串进行比较时遇到了同样的问题。以下内容对我有用,其中
控制器看起来像:
测试类看起来像:
I was having the same problem with the comparing the action to a string. the following worked for me, where
The controller looks something like:
and the test class would look something like:
有趣的是,我遵循了这里的文档: http://www.grails.org/Testing+Controllers
我打电话:
assertEquals“nextAvailable”,controller.redirectArgs.action
,我得到以下信息:
我似乎正在返回一个闭包,我正在尝试找出如何获取操作名称。
我在这里找到了解决方案:www.ibm.com/developerworks/java/library/j-grails10209/index.html?ca=drs-
如果您快速执行 ctrl/cmd + F,您会发现此断言通过:
这也通过了:
Funny, I followed the documentation here: http://www.grails.org/Testing+Controllers
I'm calling:
assertEquals "nextAvailable", controller.redirectArgs.action
and I'm getting the following:
I seem to be getting back a closure and I'm trying to figure out how to get the action name.
I found the solution here: www.ibm.com/developerworks/java/library/j-grails10209/index.html?ca=drs-
If you do a quick ctrl/cmd + F, you'll find that this assert passes:
This passes as well: