在Android集成测试中使用WireMock时出现NoSuchMethodError
在我的robotium android测试中尝试启动WireMock服务器时,获得以下堆栈跟踪。 两个版本的ApacheHTTP客户端之间可能存在冲突,但我还没有设法解决它。 有什么想法吗在Android集成测试中使用WireMock时出现NoSuchMethodError,android,wiremock,Android,Wiremock,在我的robotium android测试中尝试启动WireMock服务器时,获得以下堆栈跟踪。 两个版本的ApacheHTTP客户端之间可能存在冲突,但我还没有设法解决它。 有什么想法吗 java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLSocketFactory.<init> at com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSock
java.lang.NoSuchMethodError: org.apache.http.conn.ssl.SSLSocketFactory.<init>
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSocketFactory(HttpClientFactory.java:110)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClientConnectionManagerWithSSLSettings(HttpClientFactory.java:88)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:54)
at com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:70)
at com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.<init>(ProxyResponseRenderer.java:58)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:96)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:140)
at com.me.expertsystem.AcceptanceTest.setUp(AcceptanceTest.java:63)
java.lang.NoSuchMethodError:org.apache.http.conn.ssl.SSLSocketFactory。
位于com.github.tomakehurst.wiremock.http.HttpClientFactory.createSslSocketFactory(HttpClientFactory.java:110)
位于com.github.tomakehurst.wiremock.http.HttpClientFactory.createClientConnectionManagerWithSSLSettings(HttpClientFactory.java:88)
位于com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:54)
位于com.github.tomakehurst.wiremock.http.HttpClientFactory.createClient(HttpClientFactory.java:70)
位于com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.(ProxyResponseRenderer.java:58)
位于com.github.tomakehurst.wiremock.WireMockServer。(WireMockServer.java:96)
位于com.github.tomakehurst.wiremock.WireMockServer。(WireMockServer.java:140)
位于com.me.expertsystem.AcceptanceTest.setUp(AcceptanceTest.java:63)
恐怕从2015年第一场比赛开始,WireMock不支持Android。在这方面正在跟踪支助方面的进展
它在Roboelectric测试中运行得非常好,因为这些测试在标准JVM中运行,因此您至少可以在这方面使用它进行测试。WireMock从2016年1月起在Android应用程序中运行。这一问题在几周前通过WireMock 2.0.8-beta版本从中修复。我已经更新了它并创建了一个 以下是您需要使用它的build.gradle依赖项:
androidTestCompile("com.github.tomakehurst:wiremock:2.0.8-beta") {
//Allows us to use the Android version of Apache httpclient
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
//Resolves the Duplicate Class Exception
//Error:Execution failed for task ':app:transformClassesWithJarMergingForDebugAndroidTest'.
// > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/objectweb/asm/AnnotationVisitor.class
exclude group: 'asm', module: 'asm'
//Fixes conflict with Android's version
//Warning:Dependency org.json:json:20090211 is ignored for debugAndroidTest as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jarjar to change the class packages
exclude group: 'org.json', module: 'json'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5+'
感谢Sam对Wiremock Android支持的更新!从那时起我就转向了mockwebserver,但知道在Android环境下也可以依赖Wiremock是很有用的(我倾向于选择它而不是mockwebserver)。是的,我编写的示例项目()展示了这两个方面,但Wiremock的功能更加丰富。不利的一面是,它需要Jetty等,但它确实附带了大量依赖项。然而,它们只需要包含在androidTestCompile中,而不需要包含在您的发行版APK中。另一个缺点是,我必须启用multi-dex,甚至可以让一个演示应用程序与它一起运行。但其正面包括一把瑞士军刀,用于嘲弄和测试。