【发布时间】:2016-06-21 16:19:29
【问题描述】:
我想编写基本测试以在 /users URL 上执行 POST 请求,并使用 JSON 有效负载来创建用户。我找不到如何将新对象转换为 JSON,到目前为止有这么多,这显然是错误的,但解释了目的:
@Test public void createUser() throws Exception {
String userJson = new User("My new User", "myemail@gmail.com").toJson();
this.mockMvc.perform(post("/users/").contentType(userJson)).andExpect(status().isCreated());
【问题讨论】:
标签: json spring spring-boot