loading...

Wiremock on Heroku cloud!

sabariiish profile image Sabarish Sasidharan ・2 min read

Wiremock: WireMock is an HTTP mock server. At its core it is web server that can be primed to serve canned responses to particular requests (stubbing) and that captures incoming requests so that they can be checked later (verification).

A core feature of WireMock is the ability to return canned HTTP responses for requests matching criteria.

It can be used as a library by any JVM application, or run as a standalone process either on the same host as the system under test or a remote server.

Heroku: Heroku is a cloud platform as a service (PaaS) supporting several programming languages

The Heroku network runs the customer's apps in virtual containers which execute on a reliable runtime environment. Heroku calls these containers "Dynos." These Dynos can run code written in Node, Ruby, PHP, Go, Scala, Python, Java, or Clojure. Heroku also provides custom buildpacks with which the developer can deploy apps in any language. Heroku lets the developer scale the app instantly by either increasing the number of dynos or by changing the type of dyno the app runs in.

Setup Wiremock on Heroku

1) Create a free Heroku account (https://signup.heroku.com/dc)
2) Install Heroku CLI - https://devcenter.heroku.com/articles/heroku-cli
3) Create an application in the Heroku cloud (You can use CLI or the UI dashboard)
4) Using Heroku CLI install the java plugin: $ heroku plugins:install java
5) Deploy Wiremock:
a. Using Build Pack: Refer https://github.com/gpratte/wiremock-deploy-heroku to use the Energized Work downloadable jar buildpack.
b. Without Build Pack:
i. Refer https://github.com/sabariish/wiremock-deploy-heroku and obseve the Procfile.
ii. In the deploy tab for the Heroku application created connect the the above git hub repo
iii. Hit Deploy Branch or setup automatic deploys
6) Access the Wiremock deployed @ https://{appname}.herokuapp.com/__admin/mappings

See https://github.com/sabariish/wiremock/blob/master/src/test/java/wiremock/mock/ExampleTest.java for couple of tests which run on a hosted wiremock instance.

exampleTest – Runs a simple test which sets up a mock service (stateless rest call)
exampleScenario – Example of a stateful request

References: http://wiremock.org/docs/

Discussion

pic
Editor guide