alibaba / testable-mock

换种思路写Mock,让单元测试更简单
https://alibaba.github.io/testable-mock/
MIT License
1.83k stars 310 forks source link

添加依赖配置后,运行单元测试报错。maven项目配置,使用0.7.2和07.4版本都一样 #266

Open shuijiayou opened 2 years ago

shuijiayou commented 2 years ago

java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) Caused by: java.lang.NoClassDefFoundError: com/alibaba/testable/core/util/LogUtil at com.alibaba.testable.agent.config.PropertiesParser.parseFile(PropertiesParser.java:45) at com.alibaba.testable.agent.PreMain.premain(PreMain.java:22) ... 6 more Caused by: java.lang.ClassNotFoundException: com.alibaba.testable.core.util.LogUtil at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 8 more FATAL ERROR in native method: processing of -javaagent failed

已经参考了:https://github.com/alibaba/testable-mock/issues/156 https://github.com/alibaba/testable-mock/issues/148 没有得到解决。

linfan commented 2 years ago

看起来和 #148 是相同的问题,issue-148提交者应该是自己找到原因了,直接关闭issue但没有留下具体说明。

从报错来问题像是项目直接引用了testable-agent包,而不是文档建议的testable-all。如果单独引用testable-agent包,需要至少同时加上testable-core包,否则会在测试运行期找不到com.alibaba.testable.core.util.LogUtil这个类。

shuijiayou commented 2 years ago

我用的就是testable-all包,所以才会咨询的。不太清楚为什么用了testable-all包还这样。

linfan commented 2 years ago

尝试一下显式的添加 testable-core 依赖,是否能解决问题?