Scala中的PowerMock:java.lang.NullPointerException当getPackage

Scala中的PowerMock:java.lang.NullPointerException当getPackage,scala,testing,junit,mockito,powermock,Scala,Testing,Junit,Mockito,Powermock,这段代码只是getPackage和getName(还没有使用任何模拟技术),但失败了 有人见过这个问题吗 代码: 错误日志: [info] - test1 *** FAILED *** [info] java.lang.NullPointerException: [info] at org.apache.tmp.MyTest.test1(MyTest.scala:15) [info] at sun.reflect.NativeMethodAccessorImpl.invoke0(Na

这段代码只是getPackage和getName(还没有使用任何模拟技术),但失败了

有人见过这个问题吗

代码:

错误日志:

[info] - test1 *** FAILED ***
[info]   java.lang.NullPointerException:
[info]   at org.apache.tmp.MyTest.test1(MyTest.scala:15)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info]   at java.lang.reflect.Method.invoke(Method.java:497)
[info]   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
[info]   at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
[info]   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89)
[info]   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
[info]   at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
[info]   ...

我想我找到了答案,但我不明白为什么它会起作用

答:在sbt内部,我们应该首先“设置fork:=true”,然后一切都会正常工作

该问题可能与进程与线程问题有关

[info] - test1 *** FAILED ***
[info]   java.lang.NullPointerException:
[info]   at org.apache.tmp.MyTest.test1(MyTest.scala:15)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info]   at java.lang.reflect.Method.invoke(Method.java:497)
[info]   at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
[info]   at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
[info]   at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:89)
[info]   at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
[info]   at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
[info]   ...