簡體   English   中英

ActiveWeb:測試JSON響應屬性和值

[英]ActiveWeb: testing JSON response attributes and values

測試JSON響應(尤其是其中包含的屬性和值)的首選方法是什么? 什么樣的控制器才是正確的類型: IntegrationSpecControllerSpecAppIntegrationSpec 在相應的“ 測試”部分中找不到正確的響應。 謝謝。

如果在此示例項目中有一個很好的示例: https : //github.com/javalite/activeweb-rest/blob/27687e26f5476734b867d01f38b2575c6de3f3c9/src/test/java/app/controllers/PeopleControllerSpec.java#L57

public void shouldCreateNewPeopleWithAddresses(){

        String json = Util.readResource("/people.json");
        request().content(json.getBytes()).contentType("application/json").post("create"); // <--- need to call "create" according to REST routing

        Map response = JsonHelper.toMap(responseContent());

        the(response.get("code")).shouldBeEqual(200);
        the(response.get("message")).shouldBeEqual("successfully created people and addresses");
}

基本上,您會獲得一個String的responseContent() ,然后您可以使用它進行任何操作。 規格的超類無關。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM