Doesn't work for Android tests
See original GitHub issueI am using this lib successfully for unit tests, but when I try to use it for an instrumented Android test, I get the following: Use:
import com.nhaarman.mockito_kotlin.mock
val n: AppData = mock()
Error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/nhaarman/mockito_kotlin/MockitoKt;
at com.myproject.tests.Test.testSomething(Test.kt:91)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at com.jakewharton.u2020.U2020TestRunner.onStart(U2020TestRunner.java:22)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.nhaarman.mockito_kotlin.MockitoKt" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.myproject.test-1/base.apk", zip file "/data/app/com.myproject-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myproject.test-1/lib/x86, /data/app/com.myproject-2/lib/x86, /data/app/com.myproject.test-1/base.apk!/lib/x86, /data/app/com.myproject-2/base.apk!/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 34 more
Issue Analytics
- State:
- Created 6 years ago
- Comments:16
Top Results From Across the Web
Can't run unit tests in Android Studio - Stack Overflow
You can work around the issue by first running Make project and then Run each time you want to run the unit tests....
Read more >Test in Android Studio
Android Studio is designed to make testing simple. It contains many features to simplify how you create, run, and analyze tests.
Read more >Instrumented tests don't work on API 30 using Gradle command
We have a set of instrumented tests that run fine on Android 7,8,9, and 10 but not on Android 11 / API 30...
Read more >Unable to run common tests on Android via gutter icon in a ...
Create a new Mobile Android/iOS project via New Project Wizard in IDEA. Navigate to SampleTests.kt in commonTest . There are Run gutter icons...
Read more >Test failures in Studio don't show test output when running ...
It is possible to workaround the issue by unchecking "Run Android Instrumented tests using gradle" in settings. Issue summary. Links (3).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For the moment, you can do this workaround:
I hope it will be supported soon, in case, I can submit a PR for it.
Am I missing something? This issue is still happening, even with the mockito-android dependency added:
Error log: