1

Got the following stack trace when trying to start a WireMockServer in my robotium android test. Might be a conflict between 2 versions of Apache Http client, but I did not manage to solve it yet. Any idea?

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)
Amsheer
  • 7,046
  • 8
  • 47
  • 81
Jérôme Pietri
  • 187
  • 1
  • 11

2 Answers2

1

I'm afraid that as of 1st Match 2015 WireMock does not support Android. Progress towards support is being tracked in this github issue.

It does work quite well in Roboelectric tests because these run in a standard JVM, so you may be able use it for that aspect of testing at least.

Gareth Charnock
  • 1,166
  • 7
  • 17
1

WireMock now works in an Android app as of January 2016. This is fixed as of a couple of weeks ago with WireMock 2.0.8-beta from the 2.0-beta branch. I've updated that WireMock GitHub issue and have created a sample project showing it working.

Here are the build.gradle dependencies you'll need to use it:

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 Edwards
  • 874
  • 8
  • 19
  • 2
    Thanks Sam for your update on Wiremock Android support! I had turned to mockwebserver since, but it is useful to know that one can also rely on Wiremock in the context of an Android (I tend to prefer it over mockwebserver). – Jérôme Pietri Jan 09 '16 at 18:04
  • 1
    Yeah, the sample project (https://github.com/handstandsam/AndroidHttpMockingExamples) I wrote shows off both, but WireMock is much more feature rich. Downside is that it does come with a ton of dependencies with the need of Jetty, etc. However, they are only need to be included for androidTestCompile, not in your release APK. Another downside is that I had to enable multi-dex to get even a demo app to run with it. But the upsides includes a swiss army knife of goodness for mocking and testing. – Sam Edwards Jan 10 '16 at 03:38