1

尝试在我的机器人 android 测试中启动 WireMockServer 时得到以下堆栈跟踪。可能是 2 个版本的 Apache Http 客户端之间的冲突,但我还没有设法解决它。任何想法?

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

2 回答 2

1

恐怕截至 1st Match 2015 WireMock 不支持 Android。在这个github 问题中跟踪支持的进展。

它在 Roboelectric 测试中运行良好,因为它们在标准 JVM 中运行,因此您至少可以将它用于该方面的测试。

于 2015-03-02T17:09:48.003 回答
1

截至 2016 年 1 月,WireMock 现在可以在 Android 应用程序中使用。几周前,2.0-beta 分支中的 WireMock 2.0.8-beta 已修复此问题。我已经更新了WireMock GitHub 问题,并创建了一个示例项目,显示它正在工作

以下是您需要使用它的 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+'
于 2016-01-07T14:22:03.830 回答