java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use 解决办法

一、问题描述

在单元测试的时候报:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use 解决办法

二、原因分析

1、没有写启动类的情况

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use 解决办法

2、不在同一个包下的情况

虽然你写了启动类但是你的启动类所在的包和单元测试的包不在同一级根目录下。如上图:一个是在cn.gitv.pro.charging.sncmcc,另一个是在cn.gitv.pro.charging,他们不在同一个目录下所以报 找不到启动类:放在同一个包目录下就解决这个问题了。

java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use 解决办法

总结

单元测试的测试类一定要和启动类一定要在同一个根目录下!!!

原文地址:https://blog.csdn.net/qq_25406669/article/details/87966497