Search code examples
androidjunit5mockwebserver

unresolved supertypes: org.junit.rules.ExternalResource when using MockWebServer with Junit 5


I'm using MockWebServer from okhttp3

dependencies {
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"
    testImplementation "org.junit.jupiter:junit-jupiter-migration-support:5.0.0-M4"
    testImplementation "junit:junit:4.12"
    testImplementation "com.squareup.okhttp3:mockwebserver:4.2.1"
}

when I try to use this code:

    mockwebserver.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK))

I get the error:

e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class okhttp3.mockwebserver.MockWebServer, unresolved supertypes: org.junit.rules.ExternalResource

I've found this conversation but it did not help to fix the problem.


Solution

  • You are using the wrong artefact. The correct one is here: https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-migrationsupport It also has the corresponding version 5.5.2

    There may still be other problems but that’s the first thing to fix.