gpt4 book ai didi

java - 安心API测试中如何传递数组post请求?

转载 作者:行者123 更新时间:2023-12-02 12:26:32 25 4
gpt4 key购买 nike

我是 API 测试的新手,并试图弄清楚如何使用单个数组传递发布请求正文,该数组在放心的 API 测试中包含多组请求和属性。

{
"Transactions":
[
{"ReferenceId":"01","Id":"0727", "TCID": "67180405816294"},
{"ReferenceId":"02","Id":"0727", "TCID": "67180405816294"},
{"ReferenceId":"03","Id":"0727", "TCID": "67180405816294"}

]
}

最佳答案

听起来您想使用 restassured 将特定对象作为发布请求的正文进行发布。像下面这样的东西应该可以工作:

// 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-assured/wiki/Usage

关于java - 安心API测试中如何传递数组post请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45443356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com