Skip to content

connerT/AndroidHttpMockingExamples

 
 

Repository files navigation

Setup

  • Clone this project
  • Build the project, preferrably in Android studio.
  • This project uses the wiremock jar to be stored in build/libs folder. I have been working with the wiremock-2.0.8-beta.jar. The newest version (wiremock-2.1.0-beta.jar is failing on android because of this issue)
  • UPDATE - June 28 - wiremock-2.1.1-beta.jar is added in the repo.
  • Run the test present in AndroidHttpMockingExamples/app/src/androidTest/java/com/handstandsam/httpmocking/tests/wiremock/WireMockApplicationTestCase.java.

Build wiremock jar locally

  • Clone wiremock from https://github.com/tomakehurst/wiremock
  • Build the project - run ./gradlew build . Make sure acceptance tests are passed.
  • Copy the jar file created in build/libs and paste it into the Android projects builds/libs directory.
  • Change the wiremock's version in Android's build.gradle file to the one you imported.

HTTPS Testing

  • The BKS type keystore (android_wiremock_keystore) included should be uploaded in the /sdcard/ directory of the emulator. To do this, make sure you have emulator started. Then run open a terminal, and run
adb push <filename> /sdcard/.
  • You can also generate your own keystore using http://www.keystore-explorer.org/ or Portecle
  • If testing HTTPS, uncomment line 49 and 81 in AndroidHttpMockingExamples/app/src/androidTest/java/com/handstandsam/httpmocking/tests/wiremock/WireMockApplicationTestCase.java

These are examples by @HandstandSam - http://handstandsam.com to allow you to mock out external HTTP services on and Android device itself.

Android "androidTest" Examples for:

  • WireMock 2.0.8-beta (Android support working starting in 2.0.8-beta)
  • okhttp MockWebServer

Links

Credits

The Sample Application and Espresso Testing Logic is from the following repositories:

Thanks @yogurtearl for tips about how he got Wiremock 1.x to work on Android.

About

"androidTest" Examples for WireMock 2.x and okhttp MockWebServer 3.x

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%