第一次在使用Spock进行单元测试的Groovy/Spring项目上尝试MockWebServer。
我按照指示添加了MockWebServer依赖项(为了避免错误,我必须自己添加第二行,但它没有文档化:
testImplementation("com.squareup.okhttp3:mockwebserver:4.0.0")
testImplementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.40")我有一个基本的Spock测试,如下所示:
def 'server'() {
setup:
MockWebServer server = new MockWebServer()
expect:
server
}但是这个输出失败了:
java.lang.NoSuchMethodError: okhttp3.internal.Util.immutableListOf([Ljava/lang/Object;)Ljava/util/List;
at okhttp3.mockwebserver.MockWebServer.<init>(MockWebServer.kt:176)我还缺少另一种依赖吗?MockWebServer与Groovy和Spock玩得不好吗?
就其价值而言,使用3.1.4版本似乎有效:
testImplementation("com.squareup.okhttp3:mockwebserver:3.14.2")(我是第一次使用MockWebServer)
谢谢!
发布于 2019-07-03 04:33:03
尝试添加以下内容:
testImplementation("com.squareup.okhttp3:mockwebserver:4.0.0")
testImplementation("com.squareup.okhttp3:okhttp:4.0.0")使用MockWebServer,您的OkHttp依赖必须是相同的版本。
发布于 2019-07-07 09:23:33
我遇到了同样的问题,我在版本中找到了解决方案,只需将版本更改为"3.7.0“就可以了。
有一些关于版本更改为"3.4.1“的讨论,但是这个版本遇到了问题(不能从最终类继承),这是在这个问题上讨论的:https://github.com/andrzejchm/RESTMock/issues/56
所以最安全的版本是"3.7.0“:D
请注意,这两个版本应该是相同的。将您的依赖项更改为以下所示:
//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")https://stackoverflow.com/questions/56854548
复制相似问题