mockStatic时抛出java.lang.ExceptionInInitializerError

博客介绍了Java单元测试中解决问题的方法,即在测试类上增加注解,并填入要mock类的包名和类名,还提供了相关参考资料链接,可用于进一步学习。
Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

解决方法

在测试类上增加注解

@SuppressStaticInitializationFor("org.mycompany.ClassWithEvilStaticInitializer")

里面填上你要mock类的包名+类名

参考资料

  1. https://github.com/powermock/powermock/wiki/Suppress-Unwanted-Behavior

  2. https://stackoverflow.com/questions/38679426/java-lang-exceptionininitializererror-when-mocking-static-method-using-easymock

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

2025-12-09 17:35:58.214|ERROR|vmall_car_server|nioEventLoopGroup-3-2:155|2.0.1.66|7581789508838897024||||||Could not initialize class org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory|com.huawei.vmall.mock.impl.MockKitImpl java.lang.NoClassDefFoundError: Could not initialize class org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory at org.apache.servicecomb.swagger.invocation.Response.createConsumerFail(Response.java:178) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.decorateSyncRetry(InvokerUtils.java:284) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.innerSyncInvoke(InvokerUtils.java:198) at org.apache.servicecomb.provider.pojo.HandlerInvocationCaller.syncInvoke(HandlerInvocationCaller.java:40) at org.apache.servicecomb.provider.pojo.HandlerInvocationCaller.call(HandlerInvocationCaller.java:34) at org.apache.servicecomb.provider.pojo.Invoker.invoke(Invoker.java:71) at com.huawei.vmall.cse.reference.VmallInvoker.invoke(VmallInvoker.java:85) at jdk.proxy2/jdk.proxy2.$Proxy201.queryO2OActivityBySbomCode(Unknown Source) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at com.huawei.vmall.mock.impl.MockKitImpl.invokeRpcByCse(MockKitImpl.java:694) at com.huawei.vmall.mock.impl.MockKitImpl.pactTocheck(MockKitImpl.java:799) at com.huawei.vmall.mock.impl.MockKitImpl.contractInterface(MockKitImpl.java:763) at com.huawei.vmall.mock.impl.MockKitImpl.contractInvokeRpcInterface(MockKitImpl.java:725) at com.huawei.vmall.mock.MockTemp.contractTesting(MockTemp.java:1233) at com.huawei.vmall.mock.vo.ContractTestingVoBuilder.call(ContractTestingVoBuilder.java:180) at com.huawei.sseserver.TestPact.testQueryO2OActivityBySbomCode02_Consumer_amend(TestPact.java:30) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:76) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at com.huawei.vmall.mock.hotswap.SpringDelegateRunner.runTestInWin(SpringDelegateRunner.java:102) at com.huawei.vmall.mock.hotswap.SpringDelegateRunner.runChild(SpringDelegateRunner.java:90) at com.huawei.vmall.mock.hotswap.SpringDelegateRunner.runChild(SpringDelegateRunner.java:49) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at com.huawei.vmall.mock.hotswap.SpringDelegateRunner.run(SpringDelegateRunner.java:234) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at com.huawei.vmall.mock.hotswap.ServerHandler.runCase(ServerHandler.java:131) at com.huawei.vmall.mock.hotswap.ServerHandler.runSingleCase(ServerHandler.java:125) at com.huawei.vmall.mock.hotswap.ServerHandler.runTest(ServerHandler.java:103) at com.huawei.vmall.mock.hotswap.ServerHandler.channelRead(ServerHandler.java:43) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:796) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:732) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:658) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:1583) Caused by: java.lang.ExceptionInInitializerError: Exception java.util.ServiceConfigurationError: org.apache.servicecomb.swagger.invocation.exception.ExceptionToProducerResponseConverters: Provider org.apache.servicecomb.swagger.invocation.exception.DefaultExceptionToProducerResponseConverters could not be instantiated [in thread "nioEventLoopGroup-3-2"] at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586) at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813) at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729) at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403) at java.base/java.lang.Iterable.forEach(Iterable.java:74) at org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.loadSortedService(SPIServiceUtils.java:63) at org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.getOrLoadSortedService(SPIServiceUtils.java:95) at org.apache.servicecomb.foundation.common.utils.SPIServiceUtils.getPriorityHighestService(SPIServiceUtils.java:126) at org.apache.servicecomb.swagger.invocation.exception.ExceptionFactory.<clinit>(ExceptionFactory.java:51) at org.apache.servicecomb.swagger.invocation.Response.createConsumerFail(Response.java:173) at org.apache.servicecomb.swagger.invocation.Response.createFail(Response.java:166) at org.apache.servicecomb.swagger.invocation.AsyncResponse.fail(AsyncResponse.java:42) at org.apache.servicecomb.transport.rest.client.http.RestClientInvocation.fail(RestClientInvocation.java:292) at org.apache.servicecomb.transport.rest.client.http.RestClientInvocation.lambda$processResponseBody$8(RestClientInvocation.java:252) at org.apache.servicecomb.core.provider.consumer.SyncResponseExecutor.waitResponse(SyncResponseExecutor.java:62) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.innerSyncInvokeImpl(InvokerUtils.java:213) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.lambda$decorateSyncRetry$9828573c$2(InvokerUtils.java:272) at io.github.resilience4j.retry.Retry.lambda$decorateCheckedSupplier$3f69f149$1(Retry.java:137) at io.vavr.control.Try.of(Try.java:75) at org.apache.servicecomb.core.provider.consumer.InvokerUtils.decorateSyncRetry(InvokerUtils.java:273) ... 77 common frames omitted
最新发布
12-10
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值