IDEA测试代码覆盖率时遇到的java.lang.reflect.InvocationTargetException问题

IDEA测试代码覆盖率时遇到的java.lang.reflect.InvocationTargetException问题

在使用IDEA 的单元测试的时候,生成代码覆盖率时遇到了以下问题。

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:498)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: 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:498)
FATAL ERROR in native method: processing of -javaagent failed
    at com.intellij.rt.coverage.main.CoveragePremain.premain(CoveragePremain.java:35)
    at com.intellij.rt.coverage.main.CoveragePremain.premain(CoveragePremain.java:28)
    ... 6 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    at com.intellij.rt.coverage.instrumentation.Instrumentator.performPremain(Instrumentator.java:55)
    at com.intellij.rt.coverage.instrumentation.Instrumentator.premain(Instrumentator.java:33)
    ... 12 more

Process finished with exit code 1
Exception in thread "main"

开始毫无头绪,幸亏百度。找到了解决方案,但是其中的原因并没有弄清楚。

参考博客:https://blog.csdn.net/luzijun1992/article/details/79983710

  1. 先看一下你自己idea.exe 的位置,这是我的E:IntelliJ IDEAIntelliJ IDEA 2016.1.1in
    1

  2. 找到idea.exe.vmoptions这个文件
    2

  3. 记事本打开最后加入一行-Djava.io.tmpdir=F:Temp ,这里要注意 F:Temp 是随意写的目录,但一定要保证它存在
    3

  4. 重新打卡IDEA 在运行就可以啦。

  5. 有的idea工具用的idea64.exe,所以修改的文件是idea64.exe.vmoptions

img

原文地址:https://www.cnblogs.com/liangbin-2019-03-30/p/11504627.html