【SpringBoot】单元测试之测试Service方法

测试Service方法

@SpringBootTest

public class UserServiceTest{

@Autowired

private UserService userService;

@Test

public void findOne () throws Exception{

 Assert.assertEquals("1002",userService.findOne());

}

}

 

测试Controller接口方法

@Runwith(SpringRunner.class)

@WebMvcTest(HelloController.class)

class HelloControllerTest{

@Autowired

private MockMvc mockMvc;

@Test

public void hello()  throws Exception{

    mockMvc.perform(MockMvcRequestBuilders.post("/hello").contentType(MediaType.APPLICATION_JSON)

.andExpect(status ().isOk())

.andDo(print ());

}

}

 

相关推荐

  1. SpringBoot单元测试测试Service方法

    2024-07-20 16:10:01       20 阅读
  2. 玩转springbootSpringBoot单元测试

    2024-07-20 16:10:01       20 阅读
  3. 精通SpringBoot单元测试

    2024-07-20 16:10:01       40 阅读
  4. springboot 单元测试

    2024-07-20 16:10:01       37 阅读
  5. SpringBoot单元测试剖析

    2024-07-20 16:10:01       36 阅读
  6. SpringBoot单元测试

    2024-07-20 16:10:01       31 阅读
  7. SpringBoot单元测试

    2024-07-20 16:10:01       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 16:10:01       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 16:10:01       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 16:10:01       45 阅读
  4. Python语言-面向对象

    2024-07-20 16:10:01       55 阅读

热门阅读

  1. css样式

    css样式

    2024-07-20 16:10:01      15 阅读
  2. deque学习笔记

    2024-07-20 16:10:01       18 阅读
  3. 题解:T480715 true

    2024-07-20 16:10:01       20 阅读
  4. 你有多自律就有多自由

    2024-07-20 16:10:01       21 阅读
  5. 2024 暑假友谊赛 2

    2024-07-20 16:10:01       21 阅读
  6. 【CTFWP】ctfshow——web41

    2024-07-20 16:10:01       18 阅读
  7. Scala学习笔记19: 隐式转换和隐式参数

    2024-07-20 16:10:01       18 阅读
  8. Qmi8658a姿态传感器使用心得(2)linux

    2024-07-20 16:10:01       18 阅读
  9. springcloud与dubbo的rpc通信都是分别基于什么实现的

    2024-07-20 16:10:01       16 阅读
  10. AI论文写作软件哪些比较好用?

    2024-07-20 16:10:01       17 阅读
  11. vue-treeselect

    2024-07-20 16:10:01       22 阅读
  12. 反悔贪心

    2024-07-20 16:10:01       19 阅读
  13. 我们的耳穴项目迈进了一大步

    2024-07-20 16:10:01       21 阅读