Android - How to share dependencies between testImplementation and androidTestImplementation

September 21, 2021, at 03:40 AM

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 ""

I'm trying to understand how to properly configure my dependencies for this scenario. Help would be appreciated. Thanks.


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
   > 2 files found with path 'META-INF/AL2.0' from inputs:
      - /home/me/.gradle/caches/modules-2/files-2.1/
      - /home/me/.gradle/caches/modules-2/files-2.1/
     Adding a packagingOptions block may help, please refer to
     for more information

Still trying to work my way through this, would appreciate the help.

Rinvex laravel-addresses

Rinvex laravel-addresses

As a beginner Laravel, as using it for few weeks, I find it very frustrating and lost with Rinvex Laravel address and their instruction is a bit lost for beginner people like me, I have lookup google and seems not many details or induction on Rinvex...

Can't import from absolute paths using Typescript and NodeJS

Can't import from absolute paths using Typescript and NodeJS

I've tried many things to solve this issueI'm trying to import from absolute paths defined on my tsconfig

How to store data from user into Array or ArrayList? [closed]

How to store data from user into Array or ArrayList? [closed]

Want to improve this question? Add details and clarify the problem by editing this post

not rendering content until needed

not rendering content until needed

I am trying to make my webpage load quicker and be more responsiveI am loading in upto 4k images that a user can scroll down through, apply filters to, and sort