【发布时间】:2018-09-22 05:25:33
【问题描述】:
我正在使用 powermock.mockstatic 这条线吹,这样我就可以控制它的返回值,因为它唯一的摆动我不必测试它。
@Before
public void setUp() throws Exception
RelatedIntelligencePanel rel = Mockito.mock(RelatedIntelligencePanel.class);
PowerMockito.mockStatic(RelatedIntelligencePanel.class);
PowerMockito.whenNew(RelatedIntelligencePanel.class).withNoArguments().thenReturn(rel);
...
.. some other unrelated code
}
...........
........ some other code and Tests
......
@Test
public class SomeClass{
RelatedIntelligencePanel relIntPanel = new RelatedIntelligencePanel();
但它会抛出 java.lang.VerifyError。我做了很多嘲笑这种事情的事情,也不例外。删除 @PrepareForTest 和 @Runwith 会有所帮助,但这样做时我会失去 powermock。我的详细错误也在下面;
java.lang.VerifyError: Bad return type
Exception Details:
Location:
javax/swing/plaf/metal/MetalLookAndFeel.getLayoutStyle()Ljavax/swing/LayoutStyle @3: areturn
Reason:
Type 'javax/swing/plaf/metal/MetalLookAndFeel$MetalLayoutStyle' (current frame, stack[0]) is not assignable to 'javax/swing/LayoutStyle' (from method signature)
Current Frame:
bci: @3
flags: { }
locals: { 'javax/swing/plaf/metal/MetalLookAndFeel'}
stack {'javax/swing/plaf/metal/MetalLookAndFeel$MetalLayoutStyle'}
Bytecode:
0x0000000: b807 49b0
【问题讨论】:
标签: java exception powermock powermockito verifyerror