Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/Mockito

I'm newbie with Mockito and trying to lean from Here, All configuration I have done (Using Win-10) which mentioned in the tutorial.

Setting in Environment variable :

enter image description here

Mockito version :

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>2.0.2-beta</version>
    <scope>test</scope>
</dependency>

I've started with the example mentioned in the same. but while I do run the test my class it shows below exception :

Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/Mockito
  at com.mockitotest.PortfolioTester.setUp(PortfolioTester.java:23)
  at com.mockitotest.PortfolioTester.main(PortfolioTester.java:14)
Caused by: java.lang.ClassNotFoundException: org.mockito.Mockito
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  ... 2 more

I don't know what went wrong here. Can someone help me ?

like image 201
NarendraR Avatar asked Dec 09 '25 06:12

NarendraR


1 Answers

The scope test indicates that the dependencies (binary files) are only used using maven's test phase. They are not delivered with the final target jar though. So if you run tests yourself (rather than letting maven do it), you'd better leave the default runtime scope, as follows:

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>2.0.2-beta</version>
</dependency>
like image 196
Ahmad Shahwan Avatar answered Dec 11 '25 21:12

Ahmad Shahwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!