项目场景:springboot集成Junit在执行测试类的时候提示Failed to resolve异常

项目场景:springboot版本2.5.7,Junit版本:4.13.2,在执行测试类的时候idea提示异常:Error running ‘EsIndexHandle.deleteIndex’: Failed to resolve org.junit.platform:junit-platform-launcher:1.7.2


一、依赖引入

SpringBoot依赖版本以及Junit依赖

    <!-- Springboot 版本依赖 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.7</version><relativePath/></parent><!-- junit 依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency>

二、测试代码块

SpringBoot编写的junit单元测试类

import com.oak.expro.EsApplication;
import estool.Consts;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;@RunWith(SpringRunner.class)
@SpringBootTest(classes = EsApplication.class)
public class EsIndexHandle {@Autowiredprivate  RestHighLevelClient restHighLevelClient;@aTestpublic void deleteIndex() {deleteIndex(Consts.oldIndex);}public void deleteIndex(String index){DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(index);AcknowledgedResponse delete = null;try {delete = restHighLevelClient.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);} catch (IOException e) {System.out.println("删除索引异常:"+e.getMessage());}boolean acknowledged = delete.isAcknowledged();System.out.println("acknowledged:" + acknowledged);}
}

问题描述

错误内容如下:Error running ‘EsIndexHandle.deleteIndex’: Failed to resolve org.junit.platform:junit-platform-launcher:1.7.2

错误原因:

用junit时,IntelliJ IDEA开发工具尝试连接到Maven中央仓库,不使用开发工具中的Maven配置C:\Users\admin.m2\settings.xml,被屏蔽了访问不到

解决方案:

方案:修改pom.xml

解决方式:添加依赖

  <dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-launcher</artifactId><scope>test</scope></dependency><dependency><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId><version>5.7.0</version><scope>test</scope></dependency>

springboot集成Junit在执行测试类的时候提示Failed to resolve异常相关推荐

  1. SpringBoot集成JUnit测试

    在一些企业的实践中,要求开发人员编写测试编码来测试业务逻辑,以提高编码的质量.降低错误的发生概率以及进行性能测试等.这些IDE在创建Spring Boot应用的时候已经引入了测试包,只需要看到pom. ...

  2. SpringBoot 执行测试类取消控台台日志输出,配置只显示测试记录

    1.在 src/test/resources 创建一个 logback-test.xml 2. logback-test.xml 配置 如下: <?xml version="1.0&q ...

  3. Springboot集成Redis和Redis工具类

    目录 1.导入依赖 2.修改配置文件 3.测试 4.使用redis存入对象 5.redis自定义封装 RedisUtils工具类 1.导入依赖 <dependency><groupI ...

  4. spring、springboot项目测试类遇到的问题

    常见问题: 1.junit注解无法使用 junit依赖中添加了<scope>test</scope>junit中的注解需要在项目中src下的test文件夹(如删了或没有需要自己 ...

  5. springboot细节挖掘(对测试的支持)

    Spring Boot 提供了专门支持测试的组件 Spring Boot Test,其集成了业内流行的 7 种强大的测试框架: JUnit,一个 Java 语言的单元测试框架: Spring Test ...

  6. SpringBoot集成全局异常处理

    2019独角兽企业重金招聘Python工程师标准>>> SpringBoot集成全局异常处理 前言 对于通常的MVC项目,大量的异常需要我们去处理,如此一来,我们的 Controll ...

  7. SpringBoot集成Maven工程

    1.说明 通过Maven向导创建一个Maven Project, 而非Spring Boot向导创建Spring Starter Project, 然后通过手工修改的方式, 使这个Maven工程支持S ...

  8. springboot集成elasticsearch,实现搜索提示补全功能

    springboot集成elasticsearch,通过实体类创建索引,实现搜索提示补全功能 文章目录 springboot集成elasticsearch,通过实体类创建索引,实现搜索提示补全功能 一 ...

  9. SpringBoot 使用junit 进行测试类的编写

    SpringBoot 是最近比较火的一个框架,他几乎把Spring 对框架的整合简化的只需要动动手指就可以实现,spring Boot 把配置的Xml 去掉啦,只是用啦一个 application.p ...

最新文章

  1. JS BOM 浏览器对象模型
  2. Sicily 7974. Integer Lists 解题报告
  3. 使用mockjs模拟数据
  4. Android之moveTaskToBack()方法实现手动隐藏当前Activity
  5. 餐厅点餐系统:测试与部署
  6. TCP/IP详解卷1中文版勘误表前言
  7. centos6 5从命令行进入图形界面
  8. CMake中的ARGC ARGV 和ARGN参数意义
  9. 阿里语音识别(语音转文字)java调用全程手把手详解-适合中小学生快速上手
  10. Hibernate JPA 效率低下的原因
  11. 亲密接触Redis-第一天
  12. 注释//TODO的作用
  13. {电脑救助站}常用知识1 来自常用知识( 网络安全中起重大作用的 Windows 命令)
  14. 阿里云服务器中安装配置MYSQL数据库完整教程
  15. 大数据存储项目-基于Flink的高速公路ETC入深圳数据实时分析平台
  16. 生日礼物codeGift
  17. Studio One 5机架设置一键切换效果通道
  18. 聚智云算,向新而生| 有孚网络“专有云”开启新纪元
  19. Jetson Agx Xavier平台调试AR0820相机分辨率缩放3848x2168 to 1920x1080
  20. 每天坚持早上写日记,你会发现烦恼都没了

热门文章

  1. 11 年北漂老码农被卷跑了!他道出了离开的真相!
  2. BiFunction
  3. 关于spring与EHcache的集成
  4. 【vs】如何去掉控制台
  5. 如何隐藏控制台窗口?
  6. 百度绿萝算法2.0推出的背后
  7. Matlab_参数数量可变_笛卡尔积_Cartesian product
  8. 一件模型诉说的3d打印的变化
  9. Shift-JIS字符集判断,注意绿色的部分是ms932包含的,用getlength()方法获得的length都是1,判断成半角会出现bug
  10. 网通电信互通廉价解决方案 (转)