开发者社区> 问答> 正文

otter 里面的单元测试运行报错

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

展开
收起
古拉古拉 2023-06-18 10:25:04 152 0
1 条回答
写回答
取消 提交回答
  • 我遇到类似的问题,后来发现项目里不知为什么有时候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

    2023-06-18 11:04:11
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
移动互联网测试到质量的转变 立即下载
给ITer的技术实战进阶课-阿里CIO学院独家教材(四) 立即下载
F2etest — 多浏览器兼容性测试整体解决方案 立即下载