[英]java.lang.NoClassDefFoundError when running Android UI test with WireMockRule
I have spent quite some time trying to figure out how to fix this error while running Android Espresso test with WireMock.在使用 WireMock 运行 Android Espresso 测试时,我花了很多时间试图找出如何修复此错误。
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/protocol/HttpRequestExecutor java.lang.NoClassDefFoundError:解析失败:Lorg/apache/http/protocol/HttpRequestExecutor
The error happens at this line of code:错误发生在这行代码:
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8080));
My build.grade我的 build.grade
androidTestImplementation 'androidx.test:rules:1.1.0'
androidTestImplementation("com.github.tomakehurst:wiremock:2.18.0") {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'asm', module: 'asm'
exclude group: 'org.json', module: 'json'
exclude group: 'com.google.guava', module:'guava'
}
androidTestImplementation("org.apache.httpcomponents:httpclient-android:4.3.5.1")
More log:更多日志:
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/protocol/HttpRequestExecutor;
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:695)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:76)
at com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.<init>(ProxyResponseRenderer.java:58)
at com.github.tomakehurst.wiremock.core.WireMockApp.buildStubRequestHandler(WireMockApp.java:131)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:73)
at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:43)
at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:39)
How can I fix it?我该如何解决?
我通过使用 wiremock 独立版本来自己修复它。
androidTestImplementation "com.github.tomakehurst:wiremock-standalone:2.26.3"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.