1

I am trying to use JMockit so that I can Mock out a final method in a 3rd party jar file.

When I tried a very simple test I got the the com.sun.tools.attach.AttachNotSupportedException and after some searching around I found here that this is caused by the IBM JDK6.0 not supporting the Attach feature, and then it was suggested that the fix was to put this in my VM args:

-javaagent:C:/jars/jmockit.jar

When I did this, and re-ran, I then get the below exception.

java.lang.NoSuchMethodError: org/junit/runner/Description.getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation; at mockit.integration.junit4.internal.RunNotifierDecorator.fireTestRunStarted(RunNotifierDecorator.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:613) at mockit.internal.util.MethodReflection.invokeWithCheckedThrows(MethodReflection.java:95) at mockit.internal.annotations.MockMethodBridge.callMock(MockMethodBridge.java:76) at mockit.internal.annotations.MockMethodBridge.invoke(MockMethodBridge.java:41) at org.junit.runner.notification.RunNotifier.fireTestRunStarted(RunNotifier.java) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:48) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 

I am using JUnit4, and the JRE which comes with RAD8.5 for Websphere 8.5 development which is the IBM JRE6.0. Here are the exact JVM details:

C:\IBM\WebSphere\AppServer\java\jre\bin>.\java -version java version "1.6.0" Java(TM) SE Runtime Environment (build pwa6460_26sr3-20120810_01(SR3)) IBM J9 VM (build 2.6, JRE 1.6.0 Windows 7 amd64-64 20120809_118944 (JIT enabled, AOT enabled) J9VM - R26_Java626_SR3_20120809_1152_B118944 JIT - r11.b01_20120808_24925 GC - R26_Java626_SR3_20120809_1152_B118944 J9CL - 20120809_118944) JCL - 20120713_01 

My code is a simple empty test and so far does not use any of the features of JMockit. Here it is:

public class TestJMockit { @Test public void testJMockit() { boolean isTrue = true; assertTrue(isTrue); } } 

I am using version 1.2 of the jmockit.jar file which is the latest version at the time of writing this.

Does anyone know if it is possible at all to use JMockit on an IBM version of a JRE or is it simply impossible?

Has anyone else encountered this error before and know of a fix for it?

2
  • This problem is related to JUnit only, not the JRE. Which version is used? Should be JUnit 4.5 or newer. Also, it's best to avoid the junit.jar embedded in Eclipse (if that's the case), as it may not be as complete as the official junit.jar. Commented Jun 20, 2013 at 11:48
  • Great thanks, that's fixed it... I upgraded it to JUnit 4.11 as I was previously on JUnit 4.1. Works like a charm now. Commented Jun 21, 2013 at 2:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.