MockWebServer: java.lang.NoSuchMethodError

Try adding this:

testImplementation("com.squareup.okhttp3:mockwebserver:4.0.0")
testImplementation("com.squareup.okhttp3:okhttp:4.0.0")

With MockWebServer your OkHttp dependency must be the same version.


I got the same problem, I found the solution in version, just change the version to "3.7.0" and it's work fine.

there is some discussion about version changing to "3.4.1" but this version got the problem (Cannot inherit from final class) that discussed at this issue : https://github.com/andrzejchm/RESTMock/issues/56
so the safest version is "3.7.0" :D

just notice that both versions should be the same.. change your to dependencies to below:

//mock retrofit
testImplementation("com.squareup.okhttp3:mockwebserver:3.7.0")
testImplementation("com.squareup.okhttp3:okhttp:3.7.0")
//if your source code is java
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.40")