使用WireMockRule运行Android UI测试时出现java.lang.NoClassDefFoundErro



在使用WireMock运行Android Espresso测试时,我花了相当长的时间试图找出如何修复此错误。

java.lang.NoClassDefFoundError:未能解析:Lorg/apache/http/protocol/HttpRequestExecutor

错误发生在以下代码行:

@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8080));

我的内部版本等级

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")

更多日志:

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)

我该怎么修?

我自己用wiremock单机版修复了它。

androidTestImplementation "com.github.tomakehurst:wiremock-standalone:2.26.3"

相关内容

最新更新