以下内容在运行时导致异常:
import com.sun.net.httpserver.HttpServer; import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; import java.net.InetSocketAddress; @RunWith(PowerMockRunner.class) public class MainTest { @org.junit.Test public void main() throws Exception { HttpServer.create(new InetSocketAddress(8080), 0); } }
例外:
java.lang.VerifyError:操作数堆栈上的错误类型异常详细信息:位置:com/sun/net/httpserver/spi/HttpServerProvider $ 1.run()Ljava/lang/Object; @ 27:invokestatic原因:输入'sun/net/httpserver/DefaultHttpServerProvider'(当前帧,stack [0])不能分配给'com/sun/net/httpserver/spi/HttpServerProvider'当前帧:bci:@ 27标志:{}当地人:{ 'COM /阳光/网/的httpserver/SPI/HttpServerProvider $ 1'}堆栈:{ '太阳/网/的httpserver/DefaultHttpServerProvider'}字节码:0x0000000:B800 2599 0007 B800 27b0 B800 2699 0007 0x0000010:B800 27b0 bb00 1b59 b700 2ab8 0028 57b8 0x0000020:0027 b0
Stackmap表:same_frame(@ 10)same_frame(@ 20)在com.sun.net.httpserver.spi.HttpServerProvider.provider(HttpServerProvider.java:165)在com.sun.net.httpserver.HttpServer.create(HttpServer.java:129)在HelloWorldByHour.main(HelloWorldByHour.java:16 )在HelloWorldByHourTest.testMain(HelloWorldByHourTest.java:37)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.的java:43)在java.lang.reflect.Method.invoke(Method.java:498)在org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)在org.powermock.modules.junit4.internal .impl.PowerMockJUnit44RunnerDelegateImpl $ PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)org.junit.runners.MethodRoadie $ 2.run(MethodRoadie.java:86)at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie. java:94)at org.powermock.modules.junit4.internal.impl.P owerMockJUnit44RunnerDelegateImpl $ PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)在org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $ PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)在org.junit.internal.runners.MethodRoadie.runTest( MethodRoadie.java:84)atg.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)org.powermock.modules.unternal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207)at org位于org.junit的org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $ 1.run(PowerMockJUnit44RunnerDelegateImpl.java:120)中的.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146). org.junit.internal.runners.ClassRoadie.runProtected(ClassRoad)中的internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)ie.java:44)org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.的java:106)在org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)在org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)在有机com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)的com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)中的.junit.runner.JUnitCore.run(JUnitCore.java:159) com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
pom.xml中:
4.0.0 testPowerMock testPowerMock 1.0-SNAPSHOT org.apache.maven.plugins maven-compiler-plugin (whatever version is current) 1.8 junit junit 4.6 test org.powermock powermock-api-mockito 1.6.5 test org.powermock powermock-core 1.6.5 test org.powermock powermock-module-junit4 1.6.5 test
我认为该异常与PowerMock版本有关,因为删除该行@RunWith(PowerMockRunner.class)
会使"测试"运行毫无例外.
知道那里有什么问题吗?