Skip to main content
skill CX Codex

unit-test-wiremock-rest-api — Claude Code skill: WireMock REST API

A skill with patterns for unit testing external REST APIs through WireMock: stub responses, verify requests, simulate failures with no real network calls.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a claude-code
Open on GitHub

What unit-test-wiremock-rest-api does

This skill covers services that call third-party REST APIs. WireMock stands in for the remote endpoint, responses become stubs, and the HTTP client gets checked against data you control. Error paths are part of the package: timeouts, 4xx and 5xx replies, malformed bodies.

The instructions run in six steps. Add the WireMock dependency in test scope for Maven or Gradle. Register the extension with @RegisterExtension WireMockExtension and dynamicPort(). Point the client at wireMock.getRuntimeInfo().getHttpBaseUrl(). Declare a stub with stubFor(), call the service, assert with AssertJ, then confirm the outgoing request through verify(). A weather client test ships as the worked example, and references/advanced-examples.md holds error scenarios, body verification, timeout simulation and stateful testing.

Use a dynamic port. A fixed one breaks parallel test runs. When a stub refuses to match, look at URL encoding and header names, and reach for urlEqualTo on query parameters. Testing TLS connections means configuring TLS in WireMock. WireMock also adds overhead, so the skill itself suggests mocking at the client layer when you want faster tests.

What it helps with

  • stub an external API response inside a unit test
  • check that the client sends the right headers and query params
  • reproduce timeouts and 4xx or 5xx replies without a live server
  • drop network dependencies from integration tests
  • compare the request body against the expected API contract

Example prompts for the agent

  • write a WireMock test for the WeatherApiClient
  • stub /weather?city=London and verify the request
  • show me how to simulate an external API timeout in a test

How to install unit-test-wiremock-rest-api

1Skills CLI (Vercel)

npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a claude-code

2Manually: put the files in place

~/.claude/skills/unit-test-wiremock-rest-api/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/unit-test-wiremock-rest-api/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about unit-test-wiremock-rest-api

How do I install unit-test-wiremock-rest-api in Claude?

Run npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a claude-code. The skill lands at ~/.claude/skills/unit-test-wiremock-rest-api/SKILL.md.

What does unit-test-wiremock-rest-api do?

It supplies patterns for unit testing external REST APIs with WireMock: stubbed responses, request verification and simulated failures. No real network calls happen.

Which tools can the skill use?

Read, Write, Bash, Glob and Grep. That covers reading test code, writing new files and running the build.

Source text

SKILL.md · MIT
---
name: unit-test-wiremock-rest-api
description: Provides patterns for unit testing external REST APIs using WireMock. Stubs API responses, verifies request details, simulates failures (timeouts, 4xx/5xx errors), and validates HTTP client behavior without real network calls. Use when testing service integrations with external APIs or mocking HTTP endpoints.
allowed-tools: Read, Write, Bash, Glob, Grep
---

# Unit Testing REST APIs with WireMock

## Overview

Patterns for testing external REST API integrations with WireMock: stubbing responses, verifying requests, error scenarios, and fast tests without network dependencies.

## When to Use

- Testing services calling external REST APIs
- Stubbing HTTP responses for predictable test behavior
- Testing error scenarios (timeouts, 5xx errors, malformed responses)
- Verifying request details (headers, query params, request body)

## Instructions

1. **Add dependency**: WireMock in test scope (Maven/Gradle)
2. **Register extension**: `@RegisterExtension WireMockExtension` with `dynamicPort()`
3. **Configure client**: Use `wireMock.getRuntimeInfo().getHttpBaseUrl()` as base URL
4. **Stub responses**: `stubFor()` with request matching (URL, headers, body)
5. **Execute and assert**: Call service methods, validate results with AssertJ
6. **Verify requests**: `verify()` to ensure correct API usage

**If stub not matching**: Check URL encoding, header names, use `urlEqualTo` for query params.

**If tests hanging**: Configure connection timeouts in HTTP client; use `withFixedDelay()` for timeout simulation.

**If port conflicts**: Always use `wireMockConfig().dynamicPort()`.

## Examples

### Maven Dependencies

```xml
<dependency>
  <groupId>org.wiremock</groupId>
  <artifactId>wiremock</artifactId>
  <version>3.4.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.assertj</groupId>
  <artifactId>assertj-core</artifactId>
  <scope>test</scope>
</dependency>
```

### Basic Stubbing and Verification

```java
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.assertj.core.api.Assertions.assertThat;

class ExternalWeatherServiceTest {

  @RegisterExtension
  static WireMockExtension wireMock = WireMockExtension.newInstance()
    .options(wireMockConfig().dynamicPort())
    .build();

  @Test
  void shouldFetchWeatherDataFromExternalApi() {
    wireMock.stubFor(get(urlEqualTo("/weather?city=London"))
      .withHeader("Accept", containing("application/json"))
      .willReturn(aResponse()
        .withStatus(200)
        .withHeader("Content-Type", "application/json")
        .withBody("{\"city\":\"London\",\"temperature\":15,\"condition\":\"Cloudy\"}")));

    String baseUrl = wireMock.getRuntimeInfo().getHttpBaseUrl();
    WeatherApiClient client = new WeatherApiClient(baseUrl);
    WeatherData weather = client.getWeather("London");

    assertThat(weather.getCity()).isEqualTo("London");
    assertThat(weather.getTemperature()).isEqualTo(15);

    wireMock.verify(getRequestedFor(urlEqualTo("/weather?city=London"))
      .withHeader("Accept", containing("application/json")));
  }
}
```

See `references/advanced-examples.md` for error scenarios, body verification, timeout simulation, and stateful testing.

## Best Practices

- **Dynamic port**: Prevents conflicts in parallel test execution
- **Verify requests**: Ensures correct API usage by the client
- **Test errors**: Cover timeouts, 4xx, 5xx scenarios
- **Focused stubs**: One concern per test
- **Auto-reset**: `@RegisterExtension` resets WireMock between tests
- **Never call real APIs**: Always stub third-party endpoints

## Constraints and Warnings

- **Dynamic ports required**: Fixed ports cause parallel execution conflicts
- **HTTPS testing**: Configure WireMock TLS settings if testing TLS connections
- **Stub precedence**: More specific stubs take priority over general ones
- **Performance**: WireMock adds overhead; mock at client layer for faster tests
- **API changes**: Keep stubs synchronized with actual API contracts

## References

- [WireMock Documentation](https://wiremock.org/)
- [WireMock Stubbing Guide](https://wiremock.org/docs/stubbing/)
- `references/advanced-examples.md` - Error scenarios, body verification, timeouts

© giuseppe-trisciuoglio · MIT · giuseppe-trisciuoglio/developer-kit

Similar skills

All skills for Testing and QA →

From the same set96

unit-test-parameterized A skill that turns one JUnit 5 test method into many runs over different inputs. Useful when you need boundary coverage without copy-pasting assertions. CX Codex +1 3,800installs nextjs-authentication A skill with ready authentication patterns for Next.js 15+ App Router on Auth.js 5: providers, route protection, sessions and roles. CX Codex +1 3,800installs spring-boot-dependency-injection Sets up constructor-first dependency injection patterns for Spring Boot projects. It eliminates field injection and organizes bean selection via @Primary and @Qualifier. CX Codex +1 3,800installs nextjs-code-review Reviews Next.js App Router code before merges, covering component boundaries, Server Actions, caching and routes. Use it after a feature or router migration. CX Codex +1 3,800installs spring-boot-actuator Guides setup of Spring Boot Actuator endpoints, Kubernetes health probes, isolated management ports, and Micrometer metric exports. CX Codex +1 3,800installs spring-ai-mcp-server-patterns A skill with Spring Boot and Spring AI patterns for MCP servers: @Tool handlers, prompt templates, and stdio, HTTP or SSE transports. CX Codex +1 3,800installs nestjs-code-review A skill that reviews NestJS apps: controllers, services, modules, DI, guards and database patterns. Useful before merging a pull request. CX Codex +1 3,800installs spring-boot-resilience4j Generates Resilience4j fault tolerance patterns for Spring Boot 3.x projects. Use it to configure circuit breakers and retry logic. CX Codex +1 3,800installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor