我正在使用 Spock 插件编写 Grails 2.2.1 集成测试,其中我尝试将两组数据发布到同一控制器端点:
when: "The user adds this product to the inventory"
def postData = [productId: 123]
controller.request.JSON = postData
controller.addToInventory()
and: "Then they add another"
def secondPostData = [productId: 456]
controller.request.JSON = secondPostData
controller.addToInventory()
then: "The size of the inventory should be 2"
new JSONObject( controller.response.contentAsString ).inventorySize == 2
我看到的问题是,两个请求都将相同的 JSON 提交给 addToInventory() 。
这个 StackOverflow 问题 https://stackoverflow.com/questions/5344213/how-to-make-two-posts-with-different-contents-in-grailsintegrationtesting建议调用controller.request.reset(),但这不起作用(没有方法签名:org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpServletRequest.reset())。
我正在尝试的事情可能吗?
“Where:”可用于在 spock 测试框架中执行数据驱动测试。尝试使用以下示例:
when: "The user adds this product to the inventory"
controller.params.JSON = [productId:productId]
controller.addToInventory()
then: "The size of the inventory should be 2"
new JSONObject( controller.response.contentAsString ).inventorySize == 2
where:
ID|productId
1|123
2|456
希望有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)