I'm still fairly new to Android and Gradle, coming from a webdev/maven background. I have the MockK library which I want to use in both "normal" unit tests as well as instrumented androidTest tests. I currently have it defined as a testImplementation, however then I cannot import it into my androidTest files. I could add it twice, as a testImplementation and an androidTestImplementation:
testImplementation 'io.mockk:mockk:1.12.0'
androidTestImplementation 'io.mockk:mockk:1.12.0'
But that just feels wrong. On top of that, when I run MockKAnnotations.init() in my androidTest, I get this error:
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.mockk.proxy.android.AndroidMockKAgentFactory"
I'm trying to understand how to properly configure my dependencies for this scenario.
Edit
Ok, so I got that scenario working. I needed to use mockk for testImplementation, and mockk-android for androidTestImplementation:
testImplementation 'io.mockk:mockk:1.12.0'
androidTestImplementation 'io.mockk:mockk-android:1.12.0'
Next problem: coroutines. I've added kotlin-coroutines-test to try and help me with coroutine testing, because I get the Main dispatcher error when I try running without it.
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2"
The problem is now I get this really weird error:
Execution failed for task ':app:mergeDebugAndroidTestJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
> 2 files found with path 'META-INF/AL2.0' from inputs:
- /home/me/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna-platform/5.5.0/af38e7c4d0fc73c23ecd785443705bfdee5b90bf/jna-platform-5.5.0.jar
- /home/me/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.5.0/e0845217c4907822403912ad6828d8e0b256208/jna-5.5.0.jar
Adding a packagingOptions block may help, please refer to
https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
for more information
What can I try next?