How to Download and Install WireMock?

WireMock is a tool for mocking HTTP-based APIs that runs in the unit tests, on the desktop, or in the test environment. We can also say it is a simulator for HTTP-based APIs, considered a service virtualization tool or a mock server. It enables you to stay productive when an API you depend on

  • Doesn’t exist or
  • Isn’t complete or
  • Costly to access

It supports the testing of Edge cases and failure modes. It’s fast so reduces build time significantly. In simple terms, Wiremock is a mocking setup for integration testing. It is mainly used during the development and more significantly during the Integration testing while a system or service talks to one or multiple external or internal dependencies/services. 

Read more about WireMock in this article: Introduction to WireMock

In this article, we are going to discuss the download and installation of WireMock. 

Download and Installation of WireMock as a Standalone Process

Step 1: Go to this link and scroll to the end of the page. And download the standalone JAR file for WireMock. Refer to the below image. 

Reference article link: Jar files in Java

 

Step 2: After successfully downloading the JAR file create a folder name WireMock in your own system and move the JAR file to that folder. Open the cmd on that directory and hit the following command in order to run the JAR file.

java -jar WireMockJarFileName

Refer to the below image for more clarification. 

 

Step 3: If everything is fine then as you can see in the below image our WireMock has been started successfully and the default port number is 8080. 

 

And two other folders named __files and mappings will be created in that same WireMock folder. And you are done with the installation of WireMock as a Standalone Process.

 

Maven Dependency for WireMock

If you are using Maven as your project management tool, then in order to use the WireMock library, you need to include the following dependency in your pom.xml file

For Java 8: 

<dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8</artifactId> <version>2.33.2</version> <scope>test</scope>
</dependency>

For Java 8 standalone:

<dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8-standalone</artifactId> <version>2.33.2</version> <scope>test</scope>
</dependency>

Gradle Dependency for WireMock

Similarly, if you are using Gradle as your project management tool, then in order to use the WireMock library, you need to include the following dependency in the build.gradle file. 

For Java 8: 

testImplementation "com.github.tomakehurst:wiremock-jre8:2.33.2"

For Java 8 standalone:

testImplementation "com.github.tomakehurst:wiremock-jre8-standalone:2.33.2"