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.
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/unit-test-wiremock-rest-api/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/unit-test-wiremock-rest-api/
1Skills CLI (Vercel)
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a codex2Manually: put the files in place
.agents/skills/unit-test-wiremock-rest-api/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a cursor2Manually: put the files in place
.cursor/skills/unit-test-wiremock-rest-api/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install giuseppe-trisciuoglio/developer-kit unit-test-wiremock-rest-api2Manually: put the files in place
.github/skills/unit-test-wiremock-rest-api/SKILL.md1Skills CLI (Vercel)
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a gemini-cli2Platform CLI
gemini skills install https://github.com/giuseppe-trisciuoglio/developer-kit --path plugins/developer-kit-java/skills/unit-test-wiremock-rest-apiManually: put the files in place
.devin/skills/unit-test-wiremock-rest-api/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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