2015-05-02 42 views

回答

1

您可能需要查看GPath(Groovy表達式語言)。使用GPath可以識別特定的用戶。例如,讓我們說,從服務器返回的JSON文檔看起來是這樣的:

{ 
    "users":[ 
     { 
     "id":0, 
     "name":"Jane" 
     }, 
     { 
     "id":1, 
     "name":"John" 
     } 
    ] 
} 

然後可以使用GPATH的驗證,ID爲0的用戶名「簡」,並與ID等於用戶1被稱爲「約翰」:

then(). 
     body("users.find { it.id == 0 }.name", equalTo("Jane")). 
     body("users.find { it.id == 1 }.name", equalTo("John")). .. 

這可以變得更可重用通過使用根路徑:

then(). 
     rootPath("users.find { it.id == %d }.name"). 
     body(withArgs(0), equalTo("Jane")). 
     body(withArgs(1), equalTo("John")). .. 
+0

感謝一大堆! –

相關問題