0

我正在评估 Canoo Webtest 作为 Grails 插件的自动集成/功能测试。

我有一个我正在尝试测试的 REST 应用程序,但 Canoo Webtest似乎没有在 POST 请求中正确发送 JSON 数据。我的测试代码如下

invoke( description:"Add a product to shopping cart", 
        url:'shoppingCart/add', method:'POST', 
        content:'{"class":"shop.service.Product", "name":"A product", "description":"Manufactured by X", "price":99.9}'
        //contentFile: '../product.json'
        )

无论我使用 contentFile 方法还是将数据内联为内容属性,请求正文都是空的。测试报告显示数据已正确发送,但错误页面显示错误说明“JSONException:缺少值。在 ' 的字符 0 处。作为 GET 请求的响应的 JSON 数据恢复正常。

我已经用 curl 测试了相同的功能,它工作得非常好。Canoo Webtest 设置中是否缺少某些内容?

谢谢。

编辑:我正在使用 Grails 1.3.7 以防万一

4

1 回答 1

0

好的。我开始尝试使用invoke()并且似乎将属性soapAction值设置为 true 可以解决问题。

我不知道为什么会这样。属性的invoke() 文档说

soapAction
  Required? no
  If the HTTP method is POST and is in fact a SOAP POST request, 
  this allows the SOAP Action header to be set. Ignored for GETs.

显然它设置了一些需要的请求头。没查过是哪一个。

感谢您阅读:)

尚不能将此答案标记为正确答案,但会在可能的情况下这样做。

于 2012-11-12T22:07:05.257 回答