Android Junit test - Mockito class not found exception

I am trying to create a unit test on Android that uses the mockito-all-1.8.5.jar file from mockito.org. I added the jar file to my project using project> properties> project build path> add external jar. This always worked for me on projects other than Android.

However, when I run unit test, I get the following class exception:

java.lang.ClassNotFoundException: org.mockito.runners.VerboseMockitoJUnitRunner

Above is the following message:

Unable to load class. Make sure it is in your pharmacy. Class name: 'org.mockito.runners.VerboseMockitoJUnitRunner'. Message: org.mockito.runners.VerboseMockitoJUnitRunner

I checked the jar and the class is there.

I also tried adding at this link:

How to use and pack a JAR file with my Android application?

But, still no luck. How can I find this class?

Edit: I think there is a problem with any libraries that Mockitto depends on - they may not be compatible with jalm Dalvik. View this post:

http://daverog.wordpress.com/2009/12/14/why-android-isnt-ready-for-tdd-and-how-i-tried-anyway/

1) Import a fake framework (e.g. mockito) into the project as an additional dependency. Any imported jars containing class files that are not compiled into Dalvik bytecode (most) will not work. Attempting to compile the source with your project will not work, because most libraries will make extensive use of parts of the Java language that are incompatible with Dalvik: it uses its own library, built on a subset of the Java Apache Harmony implementation.

+4
source share
1 answer

If you are working inside the Dalvik JVM, you will not be able to use Mockito.

If you run your unit tests on your JVM desktop, however (with a testing framework like Robolectric ), then you're good to go. I am currently combining these two projects in Android.

0
source

Source: https://habr.com/ru/post/1345813/


All Articles