1

I am having issue running jmockit on idea. I have testng test case that uses jmockit to mock. I am getting:

WARNING: JMockit was initialized on demand, which may cause certain tests to fail;
please check the documentation for better ways to get it initialized.
Exception in thread "main" java.lang.reflect.InvocationTargetException
    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:597)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:108)
Caused by: java.lang.NullPointerException
    at mockit.internal.startup.Startup.redefineMethods(Startup.java:184)
    at mockit.internal.startup.Startup.redefineMethods(Startup.java:176)
    at mockit.internal.annotations.MockClassSetup.applyClassModifications(MockClassSetup.java:190)
    at mockit.internal.annotations.MockClassSetup.redefineMethodsInClassHierarchy(MockClassSetup.java:151)
    at mockit.internal.annotations.MockClassSetup.redefineMethods(MockClassSetup.java:140)
    at mockit.Mockit.setUpMocks(Mockit.java:249)
    at mockit.integration.testng.internal.TestNGRunnerDecorator.<init>(TestNGRunnerDecorator.java:67)
    at mockit.integration.testng.internal.TestNGRunnerDecorator.registerWithTestNG(TestNGRunnerDecorator.java:60)
    at mockit.integration.testng.Initializer.<init>(Initializer.java:29)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at org.testng.internal.ClassHelper.newInstance(ClassHelper.java:48)
    at org.testng.TestNG.setListenerClasses(TestNG.java:637)
    at org.testng.TestNG.configure(TestNG.java:1372)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:187)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:111)

Here is the order of jars: enter image description here

Here in part 4 it is telling what is the order and i am making this order but still getting warning which later is causing problem.

Anyone knows what is the problem? I am using

  • jdk1.6.0_25
  • Intellij idea 11.1.2
  • testng-6.3.1
  • jmockit-0.999.16
Elbek
  • 3,434
  • 6
  • 37
  • 49
  • Does http://stackoverflow.com/questions/2905735/jmockit-initialization-problem help? – Luke Woodward Dec 26 '12 at 19:06
  • Thanks for the answer. the answer is pointing the place that tells: define the order of jars. I am defining it in the picture. – Elbek Dec 26 '12 at 19:25
  • There's more advice in the answers that question than just reordering the JARs. In particular, have you tried advice in other answers, such as the one from Gary Rowe? – Luke Woodward Dec 26 '12 at 21:03
  • Yes I did, I moved jmockit to top, down. the same – Elbek Dec 26 '12 at 21:08
  • The order of jars doesn't matter when using TestNG 6.2+. However, "junit-3.8.2.jar" is also present here, and it probably shouldn't be. What happens if it is removed from the classpath? – Rogério Dec 27 '12 at 12:24
  • When I remove it still the same. What my cause the warning, If I am using TestNG 6.2+. My doubt is I am using idea, and it has this plugin internally it maybe picking up older version which may require jar's order and causing warning. I sow you are using idea too, is it possible to happen? – Elbek Dec 27 '12 at 12:53
  • The JMockit SVN repository contains ".ipr" and ".iml" IDEA files, including one module which uses TestNG, the "LoginService" sample. Currently, this is using TestNG 6.8 and IDEA 12, but it should work fine with IDEA 11 and TestNG 6.3 as well. – Rogério Dec 27 '12 at 14:47
  • There is really strange scenario: I created one project just dummy test to check if it works and it worked there. But it does not work as a part of our big project. i do use 11.1.5 IDEA version. – Elbek Dec 27 '12 at 14:52

1 Answers1

0

You are using incomplete TestNG jar from Maven, you need to use the full distribution from the TestNG site (testng.org/testng-xxx.zip), see this answers for the details:

Community
  • 1
  • 1
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • I upgraded it, Still I see the issue. I created simple project and run simple test case with @Test public void sub() { Assert.assertEquals(0, 4 - 4); } and I run the code in that project and it is working. But when I run this as a part of our project i am getting still the issue. Why idea is loading jmockit when there is no jmockit is used in test case? Thanks man for support – Elbek Dec 27 '12 at 16:00
  • Please [submit an issue](http://youtrack.jetbrains.net/issues/IDEA) with the sample project to reproduce attached. – CrazyCoder Dec 27 '12 at 16:21