0

Context

i'm trying to use jmockit with Spring boot

I'm using examples such as this: https://www.baeldung.com/mockito-vs-easymock-vs-jmockito

I have set up the agent in my IDE jvm args:

-ea -javaagent:/path/to/lib_jmockit/jmockit-1.46.jar

However the IDE cannot find the JMockit.class. Nor can gradle. Help text shows: "Cannot resolve symbol JMockit"

Intellij Cannot find JMockit.class

Some points:

  • Neither gradle nor intellij can find JMockit.class
  • I've checked the Jmockit jar files. No JMockit.class

Question

  • What class to use instead of JMockit.class?
  • can you point me to docs on how the various 'Runner' implementations work in testing? I'm new tot his and don't understand how runner "SpringJunit4ClassRunner" works differently from runner "JMockit.class" and what exactly a "Runner" implemenation does/doesn't do.

Update

I ditched JMockit for Mockito. "It just worked."

Opinionated spring boot won over opinionated tech lead.

user331465
  • 2,984
  • 13
  • 47
  • 77
  • Stupid question. Why do you want to use another mocking framework. Spring Boot uses Mockito: – Simon Martinelli Jun 13 '19 at 14:22
  • Tech lead wants likes Jmockit. I'm trying to 'give it a go.' In theory it should work. – user331465 Jun 13 '19 at 15:23
  • Either you don't have JMockit in your project's test compile classpath, or you have a newer version where the `JMockit` class no longer exists. Check the documentation. – Rogério Jun 13 '19 at 19:53
  • Tell your tech lead that Spring Boot is an opinionated framework and to get the most out of it you should use it as it is intended. This will also make update to future versions much easier. – Simon Martinelli Jun 14 '19 at 05:59
  • This should probably help you out if you're still struggling: https://stackoverflow.com/a/2906690/3175251 – RoyalBigMack Apr 10 '23 at 15:38

1 Answers1

1

I believe you just need to get rid of "@RunWith(JMockit.class)" on your test.

A few versions of JMockit ago, the API allowed you EITHER use the javaagent, or to annotate tests with @RunWith. A couple versions back, the API was changed to require javaagent, and the @RunWith was made obsolete. I believe specifying it now breaks the test.

Jeff Bennett
  • 996
  • 7
  • 18