如何在放心的 API 测试中传递数组发布请求? [英] How to pass array post request in restassured API testing?
本文介绍了如何在放心的 API 测试中传递数组发布请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 API 测试的新手,并试图弄清楚如何在可靠的 API 测试中使用单个数组传递 post 请求正文,该数组在该单个数组中包含多组请求和属性.
I am new to API testing and trying to figure out how i can pass post request body with a single array which contains multiple set of request and attributes in this single array in restasssured API testing.
{
"Transactions":
[
{"ReferenceId":"01","Id":"0727", "TCID": "67180405816294"},
{"ReferenceId":"02","Id":"0727", "TCID": "67180405816294"},
{"ReferenceId":"03","Id":"0727", "TCID": "67180405816294"}
]
}
推荐答案
听起来您想使用 restassured
将特定对象作为发布请求的正文发布.类似下面的内容应该可以工作:
It sounds like you want to post a particular object as the body of a post request using restassured
. something like the below should work:
// If you are using Object Mapping (e.g. GSON or Jackson) create your test data as java objects
List<Reference> references = ...;
TransactionDTO data = new TransactionDTO(references);
// Else, not using mapping, so create test data as string:
String data = "{ \"Transactions\": [ ...]}";
given()
.contentType("application/json")
.body(data)
.queryParam("key", "value") //omit if not needed
when()
.post("/post/url/path")
then()
.<whatever assertions you need to make>
参考:https://github.com/rest-assured/rest-放心/维基/使用
这篇关于如何在放心的 API 测试中传递数组发布请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文