SpringBoot单元测试

Posted 长不大的大灰狼

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot单元测试相关的知识,希望对你有一定的参考价值。

SpringBoot 单元测试

1、添加 Maven 依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>1.5.10.RELEASE</version>
    <scope>test</scope>
</dependency>

2、在想要测试的方法上右键,可以快速搭建测试文件夹

3、在测试方法上加上 @Test 注解:

@RunWith(SpringRunner.class)
@SpringBootTest
public class BBTestAA 

   @Autowired
   private TestRestTemplate testRestTemplate;
   
   @Test
   public void testDemo() 
    ...

以上是关于SpringBoot单元测试的主要内容,如果未能解决你的问题,请参考以下文章

springboot单元测试采坑记录

补习系列-springboot 单元测试之道

在SpringBoot中集成单元测试

在SpringBoot中集成单元测试

SpringBoot项目单元测试

springboot单元测试