2017-08-01 37 views
0

我是新來的API測試,並試圖找出如何我可以通過單個數組,其中包含多個請求和屬性在這個單一的數組中的請求和屬性在restasssured API測試。如何在重新啓動的API測試中傳遞數組發佈請求?

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

    ] 
} 
+0

不知道你在問什麼。 當你說數組包含多組「請求和屬性」時,你的意思是你想要將數組的每個元素分別提交給被測API? 也就是說,你是否希望做出3個獨立的API調用,每個調用一個數組元素,或者你希望進行一次包含_entire_數組請求體的API調用? – Ben

+0

它的一個api調用,包括整個數組請求主體... – code180681

回答

1

這聽起來像你想使用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

相關問題