WireMock is a device for mocking HTTP-based APIs that runs within the unit assessments, on the desktop, or within the take a look at surroundings. We will additionally say it’s a simulator for HTTP-based APIs, thought-about a service virtualization device or a mock server. It allows you to keep productive when an API you rely on
- Doesn’t exist or
- Isn’t full or
- Expensive to entry
It helps the testing of Edge circumstances and failure modes. It’s quick so reduces construct time considerably. In easy phrases, Wiremock is a mocking setup for integration testing. It’s primarily used through the improvement and extra considerably through the Integration testing whereas a system or service talks to 1 or a number of exterior or inside dependencies/companies.
Learn extra about WireMock on this article: Introduction to WireMock
On this article, we’re going to talk about the obtain and set up of WireMock.
Obtain and Set up of WireMock as a Standalone Course of
Step 1: Go to this hyperlink and scroll to the tip of the web page. And obtain the standalone JAR file for WireMock. Discuss with the beneath picture.
Reference article hyperlink: Jar recordsdata in Java
Step 2: After efficiently downloading the JAR file create a folder title WireMock in your individual system and transfer the JAR file to that folder. Open the cmd on that listing and hit the next command with a purpose to run the JAR file.
java -jar WireMockJarFileName
Discuss with the beneath picture for extra clarification.
Step 3: If every little thing is okay then as you may see within the beneath picture our WireMock has been began efficiently and the default port quantity is 8080.
And two different folders named __files and mappings shall be created in that very same WireMock folder. And you’re finished with the set up of WireMock as a Standalone Course of.
Maven Dependency for WireMock
If you’re utilizing Maven as your venture administration device, then with a purpose to use the WireMock library, you must embrace the next dependency in your pom.xml file
For Java 8:
<dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8</artifactId> <model>2.33.2</model> <scope>take a look at</scope> </dependency>
For Java 8 standalone:
<dependency> <groupId>com.github.tomakehurst</groupId> <artifactId>wiremock-jre8-standalone</artifactId> <model>2.33.2</model> <scope>take a look at</scope> </dependency>
Gradle Dependency for WireMock
Equally, if you’re utilizing Gradle as your venture administration device, then with a purpose to use the WireMock library, you must embrace the next dependency within the construct.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"