Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.0 (2.2 plugin)
-
None
-
None
-
Windows XP
Description
I try to run the JMockit framework in my tests to do some mocking of static classes.
I supply the argLine arguments as follows (some spaces added to avoid smileys):
<configuration>
<argLine>-javaagent : \ .m2\repository\jmockit\jmockit\0.83\jmockit-0.83.jar</argLine>
<forkMode>once</forkMode>
</configuration>
This does not work. The problem is that the Mockit class is not able to find neither the class it is suppose to mock nor the class to use as a mock. I have made two small classes, Math and MockMath each with one similar method and one static String constant. My setup-method in the testclass is as follows:
protected void setUp() throws Exception
{ super.setUp(); System.out.println(Math.TEST); System.out.println(MockMath.TEST); Mockit.redefineMethods(Math.class, MockMath.class); }When I run this, the two System.out.printlns runs Ok, and prints what it should, but the Mockit class returns the following error:
java.lang.RuntimeException: Failed to read class file for no.ergo.ec.vaktplan.MockMath
at mockit.Mockit.readClassFile(Mockit.java:228)
at mockit.Mockit.collectMockMethods(Mockit.java:191)
at mockit.Mockit.redefineMethods(Mockit.java:176)
at mockit.Mockit.redefineMethods(Mockit.java:162)
at no.ergo.ec.vaktplan.TestMain.setUp(TestMain.java:12)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:210)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:122)
at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
Caused by: java.io.IOException: Class not found
at org.objectweb.asm2.ClassReader.readClass(ClassReader.java:259)
at org.objectweb.asm2.ClassReader.<init>(ClassReader.java:236)
at org.objectweb.asm2.ClassReader.<init>(ClassReader.java:246)
at mockit.Mockit.readClassFile(Mockit.java:225)
It is not able to find the class, which was ok in the System.out run just before.
If I do a mvn eclipse:eclipse and create an eclipse project, I can run the test class without any problems in Eclipse (with exactly tha same VM arguments as I use in the pom.xml)
So I guess it is some issue with which classloader that loads the Mockit class when it is supplied as the instrumentation class via the -javaagent switch.
Anybody experience any problems like this using the -javaagent switch?
Any feedback would be greatly appreciated.
regards,
bdk
Attachments
Issue Links
- Blocked
-
SUREFIRE-1402 ......................................
- Closed
- duplicates
-
SUREFIRE-297 argLine has changed behavior from 2.2 to 2.3.
- Closed