unit-test-wiremock-rest-api

Solid

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.

Testing & QA 261 stars 29 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
81
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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</artif...

Details

Author
giuseppe-trisciuoglio
Repository
giuseppe-trisciuoglio/developer-kit
Created
7 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

Testing & QA Listed

wiremock-stub

WireMock stub conventions for HTTP integration tests. Stub mapping JSON format, scenario-based stateful stubs, request matching strategies, fault injection. Auto-loads when editing `src/test/**/*Wiremock*.java` or `**/__stubs/*.json`.

1 Updated yesterday
taipt1504
Testing & QA Solid

702-technologies-wiremock

Use when you need framework-agnostic WireMock guidance — stub design, JSON or programmatic mappings, precise request matching, response bodies and faults, classpath fixtures, isolation and reset between tests, verification of calls, dynamic ports and base URLs, and avoiding flaky stubs — without choosing Spring Boot, Quarkus, or Micronaut. Part of the skills-for-java project

393 Updated today
jabrena
DevOps & Infrastructure Solid

wiremock-standalone-docker

Provides patterns and configurations for running WireMock as a standalone Docker container. Generates mock HTTP endpoints, creates stub mappings for testing, validates integration scenarios, and simulates error conditions. Use when you need to mock APIs, create a mock server, stub external services, simulate third-party APIs, or fake API responses for integration testing.

261 Updated 1 weeks ago
giuseppe-trisciuoglio
Testing & QA Solid

132-java-testing-integration-testing

Use when you need to set up, review, or improve Java integration tests — including generating a BaseIntegrationTest.java with WireMock for HTTP stubs, detecting HTTP client infrastructure from import signals, injecting service coordinates dynamically via System.setProperty(), creating WireMock JSON mapping files with bodyFileName, isolating stubs per test method, verifying HTTP interactions, or eliminating anti-patterns such as Mockito-mocked HTTP clients or globally registered WireMock stubs. This should trigger for requests such as Review Java code for integration tests; Apply best practices for integration tests in Java code. Part of cursor-rules-java project

393 Updated today
jabrena
Testing & QA Solid

unit-test-controller-layer

Provides patterns for unit testing REST controllers using MockMvc and @WebMvcTest. Generates controller tests that validates request/response mapping, validation, exception handling, and HTTP status codes. Use when testing web layer endpoints in isolation for API endpoint testing, Spring MVC tests, mock HTTP requests, or controller layer unit tests.

261 Updated 1 weeks ago
giuseppe-trisciuoglio