java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382) at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397) Caused by: java.lang.IllegalArgumentException: Matching real methods not found for the following mocks: Object invokeMethod(reflect.Method, Object, Object[]) at mockit.internal.RedefinitionEngine.modifyRealClass(RedefinitionEngine.java:224) at mockit.internal.RedefinitionEngine.modifyRealClass(RedefinitionEngine.java:201) at mockit.internal.RedefinitionEngine.redefineMethods(RedefinitionEngine.java:185) at mockit.internal.RedefinitionEngine.setUpStartupMock(RedefinitionEngine.java:161) at mockit.internal.startup.Startup.setUpInternalStartupMock(Startup.java:175) at mockit.internal.startup.Startup.loadInternalStartupMocks(Startup.java:155) at mockit.internal.startup.Startup.initialize(Startup.java:133) at mockit.internal.startup.Startup.premain(Startup.java:117) ... 6 more FATAL ERROR in native method: processing of -javaagent failed Exception in thread "main"
原提问者GitHub用户 lralin
我遇到类似的问题,后来发现项目里不知为什么有时候maven更新会自动引入0.999.4版本的jmockit,更新下来后跑单元测试用的也是这个版本而不是pom里指定的0.999.10。把系统里的0.999.4版本清掉之后运行就正常了。怀疑应该是两个Jar包mockit.internal.startup.Startup 类的实现不同,0.999.4的版本会加载TestNGTestRunnerDecorator导致报错, 0.999.4版本有如下实现:
private static void loadInternalStartupMocks() { setUpInternalStartupMock(TestSuiteDecorator.class); setUpInternalStartupMock(JUnitTestCaseDecorator.class);
setUpInternalStartupMock(RunNotifierDecorator.class);
setUpInternalStartupMock(BlockJUnit4ClassRunnerDecorator.class);
setUpInternalStartupMock(TestNGTestRunnerDecorator.class); //加载报错
TestRun.mockFixture().turnRedefinedClassesIntoFixedOnes();
}
官方仓库里没有0.999.10,lib/install.sh导入库里 mvn clean install 找不到这个0.999.10的依赖
原回答者GitHub用户 Martian101
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。