I'm trying to run a junit test.
i'm using: junit 4.10,
easymock 3.0,
powermock-core 1.4.10 (uses javassist 3.15.0-GA),
powermock-module-junit4 1.4.10,
powermock-api-easymock 1.4.10
with all the appropriate dependencies.
I have also try with powermock-core 1.5.5(javassist 3.18.0-GA)
(please note that only one more dependency ognl (uses javassist 3.7.ga)
test class:
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClassToBeTested.class})
public class MyClassToBeTestedTest{
private MyClassToBeTested myClassToBeTested;
@Before
public void setUp() {
// Partial mock with powermock
myClassToBeTested = PowerMock.createPartialMock(MyClassToBeTested.class, "testMethod");
}
@Test // IF I COMMENT THE @Test ANNOTATION AND
public void testMethod() { // ALSO THE testMethod() THERE IS NO EXCEPTION
}
}
stack trace:
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0,08 sec
[junit]
[junit] Testcase: initializationError(com.myProject.MyClassToBeTested): Caused an ERROR
[junit] Failed to transform class with name com.myProject.MyClassToBeTested. Reason: 3
[junit] java.lang.IllegalStateException: Failed to transform class with name com.myProject.MyClassToBeTested. Reason: 3
[junit] at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:207)
[junit] at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
[junit] at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:249)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java
3)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java
)
[junit] at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
[junit] at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
[junit] at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
[junit] at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:26)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
[junit] Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
[junit] at javassist.bytecode.ByteArray.write16bit(ByteArray.java:40)
[junit] at javassist.bytecode.StackMapTable$Shifter.update(StackMapTable.java:744)
[junit] at javassist.bytecode.StackMapTable$Shifter.sameFrame(StackMapTable.java:720)
[junit] at javassist.bytecode.StackMapTable$Walker.stackMapFrames(StackMapTable.java:194)
[junit] at javassist.bytecode.StackMapTable$Walker.parse(StackMapTable.java:179)
[junit] at javassist.bytecode.StackMapTable$Shifter.doit(StackMapTable.java:714)
[junit] at javassist.bytecode.StackMapTable.shiftPc(StackMapTable.java:693)
[junit] at javassist.bytecode.CodeIterator.insertGap0(CodeIterator.java:676)
[junit] at javassist.bytecode.CodeIterator.insertGap(CodeIterator.java:636)
[junit] at javassist.bytecode.CodeIterator.insertGapCore(CodeIterator.java:467)
[junit] at javassist.bytecode.CodeIterator.insertGap(CodeIterator.java:413)
[junit] at javassist.expr.Expr.replace0(Expr.java:298)
[junit] at javassist.expr.FieldAccess.replace(FieldAccess.java:213)
[junit] at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:267)
[junit] at javassist.expr.ExprEditor.loopBody(ExprEditor.java:197)
[junit] at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
[junit] at javassist.CtClassType.instrument(CtClassType.java:1289)
[junit] at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:75)
[junit] at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:203)
thank you for any given advice...
java powermockorg.junit.Test;import org.junit.runner.RunWith;import org.mockito.Mockito;import org.powermock.core.classloader.annotations.PrepareForTest;import org.powermock.modules.junit4.PowerMockRunner;@RunWith(PowerMockRunner.class)@PrepareFo
|
this question edited Aug 5 '14 at 7:57 asked Aug 4 '14 at 15:25 sei 6 4 did you work it out yourself? – Fletch Oct 8 '14 at 15:09 No... i tried but i didn't manage to find what was the problem. I finally changed to Jmockit. – sei Oct 8 '14 at 15:23
|
1 Answers
1
I know this is an old question, but I got exactly the same error recently after changing some other dependencies. It appears to be a bug in versions of javassist pre 3.18.2 (I note you were using 3.18.1).
I fixed it by upgrading Powermock to version 1.6.2 and explicitly adding a dependency on Javassist 3.19.0-GA.
This bug was fixed in Javassist 3.18.2-GA : https://issues.jboss.org/browse/JASSIST-223
|
this answer answered Sep 9 '15 at 4:04 Jumwah 119 8
|
Recommend:java - PowerMock & JavaAssist "Failed to transform class"
sts with PowerMock. I have looked at many SO responses already, and tried many combinations of PowerMock, JUnit, JavaAssist (overriding dependencies) but can't find a combination that works for this class. (Some combinations of PowerMock, J
oriUlr:http://stackoverflow.com/questions/25122180/powermock-failed-to-transform-class-with-name-arrayindexoutofboundsexception