【发布时间】:2018-10-22 15:03:01
【问题描述】:
我在 mockMVC 中创建了 post 方法(在 spring boot 项目中) 这是我的方法测试
这是我的方法测试
@Test
public void createAccount() throws Exception {
AccountDTO accountDTO = new AccountDTO("SAVINGS", "SAVINGS");
when(addaccountService.findByName("SAVING")).thenReturn(Optional.empty());
when(addaccountService.createAccount(any())).thenReturn(createdAccountDTO);
CreatedAccountDTO createdAccountDTO = new CreatedAccountDTO("a@wp.pl", "SAVINGS", "1234rds", uuid);
mockMvc.perform(
post("/account").contentType(MediaType.APPLICATION_JSON)
.content(asJsonString(AccountNewDTO)))
.andExpect(status().isCreated())
.andExpect(header().string("location", containsString("/account/"+uuid.toString())));
System.out.println("aaa");
}
我想写GET方法。
如何在 mock mvc 中编写 get 方法?如何验证我扔的东西是否被退回?
【问题讨论】:
标签: spring-boot junit mockmvc