Springboot整合junit的方法
更新:HHH   时间:2023-1-8


这篇文章主要讲解了Springboot整合junit的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。

对maven项目的pom.xml进行配置

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
  <exclusions>
<!--junit5不需要配置junit-vintage-engine-->
    <exclusion>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
    </exclusion>
  </exclusions>
</dependency>

测试类如图所示

junit5可直接扫描测试的主启动类 也不需要加@runwith注解 只需要加@SpringBootTest 注解 也不需要指定主启动类的class文件

看完上述内容,是不是对Springboot整合junit的方法有进一步的了解,如果还想学习更多内容,欢迎关注天达云行业资讯频道。

返回编程语言教程...