giuseppe-trisciuoglio avatar

Unit Test Wiremock Rest Api

Java unit-test patterns for stubbing external REST APIs with WireMock, including error and timeout simulation.

CCM score
59 of 100
skills.sh installs
4K
GitHub stars
372
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers stubbing API responses, verifying request details, and simulating timeouts and 4xx/5xx failures
  • Includes Maven test-scope dependencies, a JUnit 5 WireMockExtension setup with dynamicPort(), and AssertJ assertions
  • Enforces dynamic ports and extension-based resets so parallel tests stay isolated and avoid real network calls
  • Designed for Java services that call external REST APIs and need fast, deterministic integration-level unit tests

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-wiremock-rest-api -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

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.

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 95

Similar to Unit Test Wiremock Rest Api

More Testing & QA