1

Despite Mockito dependency in the testImplementation, Android Studio shows red lines complaining, it can not resolve dependency.

Below is the output of dependencies task with testImplementation as configuration.

gradle :exo-audio:dependencies --configuration testImplementation



testImplementation - Implementation only dependencies for 'test' sources. (n)
+--- junit:junit:4.12 (n)
+--- org.hamcrest:hamcrest-all:1.3 (n)
+--- org.mockito:mockito-all:1.10.19 (n)
+--- com.squareup.okhttp3:mockwebserver:4.2.1 (n)
\--- com.google.dagger:dagger:2.24 (n)

(n) - Not resolved (configuration is not meant to be resolved)

Here is the screenshot of Android Studio showing errors

studio mockito error

I have tried cleaning build cache and invalidate restart, nothing seems to be working. Even I have also tried by removing .idea and .gradle directories manually and loading project again.

I think the problem is with Android Studio, even with studio complaining about the classes, I am able to run tests e.g. for the following test hash code is printed.

@Test
    fun foo() {
        println(repository.hashCode())
    }
mallaudin
  • 4,744
  • 3
  • 36
  • 68

1 Answers1

2

Finally! I have resolved it at the end of the day. I will list down the steps I performed.

  1. Checked test source directores and classpath in module.iml file, everything looked fine here

    <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
    
  2. Checked versions available in local gradle cache

    allaudin@geek ~/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core$ ls
    
    1.10.19  2.10.0  2.19.0  2.27.0  2.28.0  2.28.2  2.6.1  2.7.22
    

Finally I tried with different version, it didn't work for versions till 2.10.0 and then started working for version 2.19.0.

I tried to figure out the root cause but I have to code a lot before I go to sleep. Over to experts for figuring out why some versions do not work ;)

mallaudin
  • 4,744
  • 3
  • 36
  • 68