一. 测试一般程序(Service/DAO/Util类)

1. 在pom.xml中引入依赖

SpringBoot 集成测试

2. 生成测试类

<1> 如果使用IntelliJ IDEA,可以使用快捷键直接生成:

  • Windows快捷键:Ctrl + Shift + T
  • Mac快捷键:Commond + Shift + T
  • SpringBoot 集成测试

     

     SpringBoot 集成测试

     

     

     

3. 编写测试类

1.使用@SpringBootTest进行测试,使用TestRestTemplate测试Controller类

<1> 在测试类上加入@RunWith(SpringRunner.class) 与@SpringBootTest 注解,
<2> 编写测试方法并添加@Test注解

SpringBoot 集成测试

 

 

 

2. 使用@WebMvcTest 注解测试

<1> 在测试类上加入@RunWith(SpringRunner.class) 与 @WebMvcTest 注解
<2> 使用MockMvc对象测试

SpringBoot 集成测试

 

 

 
 
 
 
 

相关文章:

  • 2021-12-24
  • 2021-06-19
  • 2022-12-23
  • 2021-09-29
  • 2021-07-29
  • 2022-12-23
  • 2021-08-29
  • 2021-04-20
猜你喜欢
  • 2022-12-23
  • 2022-01-28
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
相关资源
相似解决方案