giuseppe-trisciuoglio avatar

Unit Test Wiremock Rest Api

This gives you WireMock patterns for testing REST API integrations without hitting real endpoints. Stub responses, verify request details like headers and query params, and simulate failures (timeouts, 500 errors, malformed JSON). It uses JUnit 5 extensions with dynamic ports to avoid conflicts in parallel test runs. The examples cover basic stubbing and verification, with references to advanced scenarios for body matching and stateful mocking. If you're writing services that call external APIs and want fast, deterministic tests that don't depend on network state or third-party availability, this is the standard approach. Just make sure you keep your stubs in sync with actual API contracts.

skills.sh installs
3.9K
GitHub stars
369
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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.

Sponsors

Details

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

More from giuseppe-trisciuoglio/developer-kit

All 102
1aj-geddes avatarrest-api-designaj-geddes/useful-ai-promptsDesign RESTful APIs following best practices for resource modeling, HTTP methods, status codes, versioning, and documentation. Use when creating new APIs, desig2.1Kskills.sh installs
2manutej avatarpostgresql-database-engineeringmanutej/luxor-claude-marketplaceComprehensive PostgreSQL database engineering skill covering indexing strategies, query optimization, performance tuning, partitioning, replication, backup and 1.8Kskills.sh installs
3ruvnet avataragent-dev-backend-apiruvnet/rufloAgent skill for dev-backend-api - invoke with $agent-dev-backend-api1.1Kskills.sh installs
4secondsky avatarrest-api-designsecondsky/claude-skillsDesigns RESTful APIs with proper resource naming, HTTP methods, status codes, and response formats. Use when building new APIs, establishing API conventions, or600skills.sh installs
5manutej avatarrest-api-design-patternsmanutej/luxor-claude-marketplaceComprehensive guide for designing RESTful APIs including resource modeling, versioning strategies, HATEOAS, pagination, filtering, and HTTP best practices527skills.sh installs
6kubesphere avatarkubesphere-gateway-apikubesphere/kubesphereKubeSphere Gateway API extension management Skill (Traefik based, uses Kubernetes Gateway API + GatewayProxy CRD gatewayapi.kubesphere.io/v1alpha1). This is the0skills.sh installs