SpringMVC/ mockMVC/ jsonpath compare list of strings

前端 未结 2 1881
予麋鹿
予麋鹿 2020-12-24 13:42

I am currently writing some unit tests for a Spring MVC project. As the returned media type is JSON, I try to use jsonPath to check if the correct values are returned.

2条回答
  •  一向
    一向 (楼主)
    2020-12-24 14:19

    Here is what I ended up using:

    .andExpect(jsonPath('$.data.roles').value(Matchers.hasSize(size)))

    and

    .andExpect(jsonPath('$.data.roles').value(Matchers.containsInAnyOrder("role1", "role2", "role3")))

提交回复
热议问题