小编mar*_*ine的帖子

springmockMVC测试方法GET

我在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");
}
Run Code Online (Sandbox Code Playgroud)

我想写GET方法。

如何在mock mvc中编写get方法?如何验证我扔的东西是否被退回?

junit spring-boot mockmvc

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

junit ×1

mockmvc ×1

spring-boot ×1