Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: Mockito Bytebuddy

I recently added Mockito to a maven project on eclipse, by adding the external jar "mockito-core-2.0.53-beta.jar", and upon attempting to create my first mock object (Line two in the function)

enter image description here

And upon running it, the console prints out the first line, then throws this error:

enter image description here

It seems like previously there was a similar issue, but it was supposedly fixed internally. https://github.com/raphw/byte-buddy/issues/99

What is going wrong here?

like image 951
efong5 Avatar asked May 24 '16 18:05

efong5


3 Answers

You simply forgot to add the dependencies to your project which are according to the pom file:

<dependency>
  <groupId>net.bytebuddy</groupId>
  <artifactId>byte-buddy</artifactId>
  <version>1.3.16</version>
  <scope>runtime</scope>
</dependency>
<dependency>
  <groupId>org.objenesis</groupId>
  <artifactId>objenesis</artifactId>
  <version>2.1</version>
  <scope>runtime</scope>
</dependency>

In other words you need to add byte-buddy 1.3.16 and objenesis 2.1 to your project too.

More details here

like image 139
Nicolas Filotto Avatar answered Oct 16 '22 18:10

Nicolas Filotto


Instead adding

mockito-core

better option will to add

mockito-all

Refer to this link https://mvnrepository.com/artifact/org.mockito/mockito-all/2.0.2-beta

like image 25
Jyotirup Avatar answered Oct 16 '22 20:10

Jyotirup


There is a post that explain the problem pretty well, you can find it here:

https://solidsoft.wordpress.com/2012/09/11/beyond-the-mockito-refcard-part-3-mockito-core-vs-mockito-all-in-mavengradle-based-projects/

If you are not using gradle or maven and you are just using mockit-core you should add these dependencies:

<dependency>
  <groupId>net.bytebuddy</groupId>
  <artifactId>byte-buddy</artifactId>
  <version>1.7.9</version>
  <scope>runtime</scope>
</dependency>
<dependency>
  <groupId>org.objenesis</groupId>
  <artifactId>objenesis</artifactId>
  <version>2.4</version>
  <scope>runtime</scope>
</dependency>
like image 43
Miguel Gomes Avatar answered Oct 16 '22 19:10

Miguel Gomes