【发布时间】:2020-03-02 08:04:35
【问题描述】:
我正在使用 JUnit5 进行集成测试。我有一个需要传递到终点的对象列表。 Mockmvc 的 content 参数只接受字符串。我怎样才能传递这个对象?任何想法将不胜感激。
这是我的代码
Customer cust1 = Customer.builder().name("Syed")
.location("India").build();
Customer cust2 = Customer.builder().name("Ali")
.location("India").build();
List<Customer> customers = Arrays.asList(cust1, cust2); --> This needs to be passed.
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/process")
.content(customers) --> Compilation error here
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
我该如何解决
【问题讨论】: