2012-11-15 56 views
0

Grails的动作,我有简单的代码的Grails:无法从JUNIT Grails的

def myAction={ render("some string" as JSON)} 

现在我想访问和测试访问渲染JSON对象这个渲染JSON在Junit.I试图controller.renderArgs,controller.renderArgs .JSON.as以及测试

def ret=controller.myAction();ret.JSON 

以及一些可能的其他一些ways..but不能capture.Is有什么办法可以捕捉渲染JSON对象在JUnit的Grails ..?

在此先感谢..

回答

0

如果您使用的Grails 2.x中,你可以做

def json = controller.response.json 

,这将给你一个JSON对象(XML也适用)。

如果您使用的是版本< 2.X那么你就需要做一些事情,如:

def json = JSON.parse(controller.response.contentAsString)