4.4微服务版本单元测试提示Unable to find a @SpringBootConfiguration找不到

Blade 未结 1 52
pjf
pjf 剑童 2025-06-11 16:02

一、该问题的重现步骤是什么?

  1. 首先引入jarblade-core-test

2. 创建测试类,内容如下

(.)
(appName = ,profile = , enableLoader = )
{
    () {}


}

3.在nacos上配置了test的配置文件后,添加了一个LauncherService的实现类

(.)
{

    (, , , ) {
       = .();
       .setProperty(, .);
       .setProperty(, .);
       .setProperty(, .);
    }

}

这里AutoService会报错提示找不了,之后有在pom中添加的auto的jar

以下是文件的结构image.png

二、你期待的结果是什么?实际看到的又是什么?

完成上述配置后,运行测试类提示:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test


然后我看了一下社区,在BaldeTest类上添加添加了如下注解

@SpringBootTest(classes = WorkApplication.class)

此时报错:

java.util.ServiceConfigurationError: org.springblade.core.launch.service.LauncherService: Provider org.sprinblade.test.launch.LauncherTestServiceImpl not found


at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)

at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219)

at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)

at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)

at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)

at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)

at java.base/java.lang.Iterable.forEach(Iterable.java:74)

at org.springblade.core.test.BladeSpringExtension.setUpTestClass(BladeSpringExtension.java:89)

at org.springblade.core.test.BladeSpringExtension.beforeAll(BladeSpringExtension.java:53)

at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)


我该如何正确的完成微服务的单元测试

三、你正在使用的是什么产品,什么版本?在什么操作系统上?

balde 4.40微服务版本    window 11操作系统

四、请提供详细的错误堆栈信息,这很重要。


五、若有更多详细信息,请在下面提供。

1条回答
代码语言
提交回复