解决SpringBoot运行Test时报错:SpringBoot Unable to find

目录
  • SpringBoot运行Test时报错
    • 错误详情
    • 解决办法
  • SpringBootTest单元测试报错

SpringBoot运行Test时报错

运行Test时的报错信息:SpringBoot Unable to find a @SpringBootConfiguration

错误详情

今天做SpringBoot配置邮件发送的时候,运行测试类,报如下错误:

说找不到@SpringBootConfiguration注解,其实是有的,检查了下启动类和被测试类的细节,都没问题,查询的很多CSDN答案都是互相抄来抄去。。。。比如测试类的包名和启动类的包名一致等解决办法,试了都没用。

解决办法

原来还要在测试类里制定启动类。。。解决办法很简单,把@SpringBootTest()注解改成@SpringBootTest(classes = App.class)就可以了。就像这样:

注:我这里的启动类名为App,更改的时候根据自己启动类名来改

SpringBootTest单元测试报错

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { DataRulesApplication.class })
@EnableAutoConfiguration
//@SpringBootTest(classes = { DataRulesApplication.class })
public class HuaboAddressTest extends AbstractTestNGSpringContextTests {
    @Autowired
    private HuaboAddressServiceImpl johnyService;

    @Test
    public void queryState() {
        //johnyService.resetAllDistricts();
        long startTime = System.currentTimeMillis();
        //    johnyService.resetAllDistricts();
        //  johnyService.batchUpdate2();
        //  johnyService.batchupdate3();
        //johnyService.resetAllDistricts();
        johnyService.updateBatch();
        long endTime = System.currentTimeMillis();
        System.out.println("执行时间:" + (endTime - startTime));

//        long startTime = System.currentTimeMillis();
//        johnyService.select1();
//        long endTime = System.currentTimeMillis();
//        System.err.println("执行时间1:"+(endTime-startTime));
//        startTime = System.currentTimeMillis();
//        johnyService.select2();
//        endTime = System.currentTimeMillis();
//        System.err.println("执行时间2:"+(endTime-startTime));
    }

    @Test
    public void check() {
    }

    @Test
    public void register() {
    }

    @Test
    public void detail() {
    }

    @Test
    public void queryCategory() {
    }
}

其实只需要在setting中设置运行test的环境即可。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • SpringBoot+TestNG单元测试的实现

    目录 背景 接口测试用例,针对入参进行设计: 言归正传! 背景 由于开发任务进度紧张,接口及基础数据提供不全,即使设计全面的接口测试用例也无法全面有效的进行覆盖测试:且又因为单接口测试用例设计的方向是入参和出参,从入参着手就是参数必填校验.参数类型及参数边界值,再有入参的组合入参,例如一个接口5个参数,3个必填,2个非必填,数据类型有string.int等,还有字符长度限制条件,那么这样的单接口测试用例数设计起来那就有,嗯......数不过来,如果入参个数及参数类型变得多起来,那么这个数量就不可

  • SpringBootTest单元测试报错的解决方案

    目录 SpringBootTest单元测试报错 单元测试 @mock和@SpringBootTest使用 一.单元测试工具mock使用 二.springboot使用@SpringBootTest单元测试 三.mock和@springBootTest区别 SpringBootTest单元测试报错 @RunWith(SpringRunner.class) @SpringBootTest(classes = { DataRulesApplication.class }) @EnableAutoConf

  • 解决@SpringBootTest 单元测试遇到的坑

    目录 @SpringBootTest单元测试的坑 1.环境 2.遇到的问题 3.解决方式 Test类运行单元测试失效 Test测试类无法执行完全问题 @SpringBootTest单元测试的坑 1.环境 spring boot 版本:2.4.3 2.遇到的问题 (1)@Before.@After 失效 (2)org.junit.runners.model.InvalidTestClassError: 3.解决方式 注意 import 的 junit 包的配套问题 #junit5 配套 impor

  • Springboot使用test无法启动问题的解决

    Springboot使用test无法启动 test无法启动,遇到 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use报错信息 测试文件和启动文件是否才同一层目录下 SpringBootTest--踩坑错误 Spring boot降低了我们对spring开发的难度 采用了大量在的自动配置,我们只需要进行简单的基本配置,就能快速开发一个spring应用. 同样sprin

  • 单元测试 @mock与@SpringBootTest的使用

    目录 一.单元测试工具mock使用 1.引入依赖包 2.mock测试类 二.springboot使用@SpringBootTest单元测试 1.引入依赖包 2.测试类 三.mock和@springBootTest区别 1.mock进行单元测试不依赖spring的bean定义文件 2.@springBootTest需要启动服务 单元测试--SpringbootTest和MockMvc SpringbootTest MockMvc类的使用和模拟Http请求 相关API: 在写单元测试的过程中我们会发

  • SpringBootTest--踩坑错误的解决

    目录 SpringBootTest 踩坑 SpringBootTest的一个小坑注意点 1.我当时运行SpringBoot测试类的时候踩这个坑 2.解决方法 SpringBootTest 踩坑 Spring boot降低了我们对spring开发的难度 采用了大量在的自动配置,我们只需要进行简单的基本配置,就能快速开发一个spring应用.同样spring对于单元测试也有场景启动器----spring-boot-starter-test,可以让我们在,spring环境下进行测试. 昨天测试的时候,

  • 解决SpringBoot运行Test时报错:SpringBoot Unable to find

    目录 SpringBoot运行Test时报错 错误详情 解决办法 SpringBootTest单元测试报错 SpringBoot运行Test时报错 运行Test时的报错信息:SpringBoot Unable to find a @SpringBootConfiguration 错误详情 今天做SpringBoot配置邮件发送的时候,运行测试类,报如下错误: 说找不到@SpringBootConfiguration注解,其实是有的,检查了下启动类和被测试类的细节,都没问题,查询的很多CSDN答案

  • 解决python运行启动报错问题

    问题一: python启动报错api-ms-win-crt-process-l1-1-0.dll 丢失 解决: 下载api-ms-win-crt-process-l1-1-0.dll文件丢到C:\Windows\SysWOW64(64位操作系统).C:\Windows\System32(32位操作系统)目录下 问题二: python运行时错误代码(0xc000007b) 解决: 下载directxrepair工具修复系统文件,修复成功后手动重启电脑 补充知识:Python3开启自带http服务

  • 解决springboot 连接 mysql 时报错 using password: NO的方案

    最近使用 springboot 配置 mysql 时出现了一个错误 Access denied for user ''@'localhost' (using password: YES) 或者 Access denied for user ''@'localhost' (using password: NO) 经发现这是 springboot 中 yml 语法的的一个坑,在我现在用的最新版本2.2.4 的springBoot中所推荐 yml 的格式是 data-username: root da

  • 解决Mysql服务器启动时报错问题的方法

    一.概述 文章主要介绍因为启动mysql服务报错引发的问题:"ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)",顺带扩充一些其它的知识点,当前版本是red hat 6,mysql 5.6. 二.步骤 报错的源头 问题解决 1.权限 报错的源头就是它了,一般这种问题首先会想到的就是权限问题,就是/var/lib/mysql该文件夹的权限 上图可以看到my

  • IntelliJ IDE运行Tomcat报错解决办法

     IntelliJ IDE运行Tomcat报错解决办法 由于Tomcat默认关闭JMX功能,但IntelliJ IDE配置的IDE需要提供JMX功能,所以IntelliJ IDE运行Tomcat报错:Unable to ping server at localhost:1099! 解决的办法: 1.为Tomcat开启JMX功能,比较麻烦. 2.不使用JMX功能,修改host文件: 127.0.0.1 localhost [添加计算机名] 例如我的计算机名为Linux,所以设置为 127.0.0.

  • 解决使用RestTemplate时报错RestClientException的问题

    目录 使用RestTemplate时报错RestClientException 这是自己封装的一个发送请求的方法 这是自定义的一个http信息Converter RestTemplate的错误处理 问题描述 ErrorHandler 解决办法 使用RestTemplate时报错RestClientException 这是自己封装的一个发送请求的方法 public Map<String, Object> sendRequest(Map<String, Object> body,Str

  • springboot中pom.xml文件注入test测试依赖时报错的解决

    目录 pom.xml文件注入test测试依赖时报错 分析原因 解决方法 springboot中pom.xml之间的依赖 依赖关系 所用到的技术 talkischeap,详见配置文件 pom.xml文件注入test测试依赖时报错 报错:Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-test:jar:2.0.4.RELEASE 分析原因 有可能是默认版本太高 解决方法 降低版本

  • springBoot集成Elasticsearch 报错 Health check failed的解决

    springBoot集成Elasticsearch 报错 Health check failed 今天集成Elasticsearch 时启动报错 报错信息如下: 2018-11-01 20:52:51.310 INFO [hstao-supersearch,,,] 8528 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8009 2018-11-01 20:52:51.314 INFO [hstao

  • SpringBoot启动yaml报错的解决

    SpringBoot启动yaml报错 报错找不到org.yaml里的一个方法 10:45:54.742 [main] ERROR org.springframework.boot.SpringApplication - Application run failed java.lang.NoSuchMethodError: org.yaml.snakeyaml.nodes.ScalarNode.getScalarStyle()Lorg/yaml/snakeyaml/DumperOptions$Sc

  • 解决SpringBoot中@Email报错问题

    JSR303校验相关 现象:在springboot中使用@Email注解进行数据校验时,报没有该注解的错误. 解决方法: 在pom.xml中加该配置 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> 测试成功 ==测试成功== ![i

随机推荐