SpringBoot@Test测试单元运行时报错:Failed to resolve org.junit.platform:junit-platform-launcher:1.10.3(已解决)

今天在写项目,进行一个方法测试时报错:Error running 'JWTTest.testCreateJWT': Failed to resolve org.junit.platform:junit-platform-launcher:1.10.3

        问题原因一:没有导入Junit的依赖:

        在使用Spring Initializr创建项目时,一般会自动导入Junit的依赖,看pom.xml中有没有,没有就导入:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>

        问题原因二:只导入了Junit的依赖没有导入junit-platform-launcher依赖

  再导入下面这个测试运行依赖即可成功:

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <scope>test</scope>
</dependency>

具体来说,junit-platform-launcher 的作用包括:

  1. 发现和执行测试:它负责从测试计划(test plans)中发现和执行测试。这些测试可以是使用 JUnit Jupiter、JUnit Vintage(用于运行旧版本的 JUnit 测试)或其他任何遵循 JUnit Platform 测试引擎 API 编写的测试。

  2. 支持 IDE 和构建工具:它提供了与 IDE(如 IntelliJ IDEA、Eclipse)和构建工具(如 Maven、Gradle)的集成,使得这些工具能够利用 JUnit Platform 的功能来发现和执行测试。

        此外,JUnit 5 还提供了其他相关的依赖,如 junit-jupiter-engine(JUnit Jupiter 测试引擎实现)和 junit-vintage-engine(JUnit Vintage 测试引擎实现,用于运行旧版本的 JUnit 测试)。这些依赖可以根据项目的需要进行选择和添加。

       

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值