IntelliJ IDEA 2024.1 Help

WireMock

IntelliJ IDEA provides support for WireMock, a tool for stubbing HTTP services. Stubbing involves creating stubs or set responses to API calls that mimic real API behavior without the need for actual server communication.

Install the WireMock plugin

This functionality relies on the WireMock plugin, which you need to install and enable.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Plugins.

  2. Open the Marketplace tab, find the WireMock plugin, and click Install (restart the IDE if prompted).

Create WireMock stubs

Create basic WireMock stub from scratch

If a JSON file is placed in the mappings folder or contains the "mappings" key, IntelliJ IDEA recognizes it as a WireMock stub file and provides appropriate coding assistance.

  1. In the Project tool window, right-click a folder (or press Alt+Insert) and select New | File.

  2. In the New File dialog that opens, enter a name of the file. For example, you can enter mappings/my-stub.json, and IntelliJ IDEA will create the mappings folder and place the new file within it.

  3. Start typing a key to get suggestions for applicable keys and their quick documentation.

Wiremock Coding Assistance

Create WireMock stubs from Endpoints tool window

  1. Open the Endpoints tool window (View | Tool Windows | Endpoints).

  2. Right-click an endpoint and select Generate WireMock Stubs.

Creating WireMock stub from Endpoints

The new stub file is saved as a scratch under Scratches and Consoles | WireMock Stubs.

Create WireMock stubs from OpenAPI specification

  1. Open an OpenAPI specification file.

  2. Click and select Generate WireMock Stubs. Right-click an endpoint and select Generate WireMock Stubs.

Creating WireMock stub from Endpoints

The new stub file is saved as a scratch under Scratches and Consoles | WireMock Stubs.

Run WireMock server

  1. Open your stub file.

  2. Click Run WireMock in the upper-right part of the editor.

    Run WireMock

This will start the WireMock server, and you can see it running in the Services tool window (View | Tool Windows | Services or press Alt+8).

WireMock in Services

To customize how IntelliJ IDEA starts the WireMock server, you can modify the WireMock run configuration or create a new one.

Send HTTP requests

Use the IntelliJ IDEA HTTP Client to send HTTP request to the WireMock server and preview responses.

  1. Run your WireMock server.

  2. Open your stub JSON file.

  3. Place the caret at your endpoint URL, press Alt+Enter (Show Context Actions), and select Generate request in HTTP Client.

You can view the stub response in the Services tool window.

HTTP request to WireMock stub

WireMock run configuration

IntelliJ IDEA comes with a dedicated WireMock run configuration, which allows you to customize how to start the WireMock server.

WireMock run configuration

Main parameters

Name

Specify a name for the run configuration.

Stubs file

Location of the JSON file with WireMock stubs to run.

Server port

HTTP port number for the WireMock server. Enter 0 to dynamically determine a port.

Modify options

Verbose output

Turn on verbose logging to stdout (equivalent for the --verbose option).

JRE

Select a JRE if you wish to run WireMock in a different runtime environment than JBR.

Logs

Specify which log files generated while running the application should be displayed in the console on the dedicated tabs of the Run tool window.

Before launch

Select tasks to be performed before starting the selected run/debug configuration.

Last modified: 17 April 2024