如何在放心的 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>