702-technologies-wiremock

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

WireMock best practices

WireMock 最佳实践

Help teams use WireMock effectively for HTTP dependency stubbing with stable, isolated tests.
What is covered in this Skill?
  • Stub isolation: per-test registration,
    resetAll()
    , avoiding leaked global stubs
  • Request matching: method, path, headers, query, body patterns; when broad patterns are acceptable
  • Responses: status, headers, JSON/XML bodies,
    bodyFileName
    / classpath fixtures, fault simulation (delays, errors)
  • Dynamic ports and propagating base URLs into the system under test
  • Verification of outbound HTTP calls and debugging unmatched requests
  • Clear delegation to framework integration-test skills for test class layout and extensions
Scope: Portable WireMock behavior only. For
BaseIntegrationTest
,
WireMockExtension
, and stack-specific integration tests, use
@132-java-testing-integration-testing
,
@322-frameworks-spring-boot-testing-integration-tests
,
@422-frameworks-quarkus-testing-integration-tests
, or
@522-frameworks-micronaut-testing-integration-tests
. For OpenAPI contract quality, use
@701-technologies-openapi
.
帮助团队有效使用WireMock进行HTTP依赖项存根,实现稳定、隔离的测试。
本技能涵盖哪些内容?
  • 存根隔离:每测试注册、
    resetAll()
    、避免全局存根泄漏
  • 请求匹配:方法、路径、请求头、查询参数、请求体模式;何时可使用宽泛模式
  • 响应处理:状态码、响应头、JSON/XML响应体、
    bodyFileName
    /类路径 fixture、故障模拟(延迟、错误)
  • 动态端口及将基础URL传递到被测系统
  • 验证出站HTTP调用并调试未匹配的请求
  • 明确委托给框架集成测试技能处理测试类布局与扩展
适用范围:仅适用于可移植的WireMock行为。如需了解
BaseIntegrationTest
WireMockExtension
以及特定技术栈的集成测试,请使用
@132-java-testing-integration-testing
@322-frameworks-spring-boot-testing-integration-tests
@422-frameworks-quarkus-testing-integration-tests
@522-frameworks-micronaut-testing-integration-tests
。如需OpenAPI契约质量相关内容,请使用
@701-technologies-openapi

Constraints

约束条件

Keep recommendations at the WireMock and HTTP-stub layer unless the user explicitly asks for framework integration. After editing this repository's XML sources, regenerate skills and verify the build.
  • MANDATORY: Run
    ./mvnw compile
    or
    mvn compile
    before proposing Java or Maven changes in the same change set
  • FRAMEWORK: Defer
    @SpringBootTest
    /
    @QuarkusTest
    /
    @MicronautTest
    and extension setup to
    @132-java-testing-integration-testing
    or the matching
    322
    /
    422
    /
    522
    integration-test skill
  • CONTRACTS: Defer OpenAPI document structure and linting to
    @701-technologies-openapi
  • MANDATORY: Regenerate skills with
    ./mvnw clean install -pl skills-generator
    after editing skill or system-prompt XML in this repo
  • VERIFY: Run
    ./mvnw clean verify
    or
    mvn clean verify
    before promoting changes
除非用户明确询问框架集成相关内容,否则仅在WireMock和HTTP存根层面给出建议。编辑本仓库的XML源文件后,需重新生成技能并验证构建。
  • 强制要求:在同一变更集中提交Java或Maven修改前,先运行
    ./mvnw compile
    mvn compile
  • 框架相关:将
    @SpringBootTest
    /
    @QuarkusTest
    /
    @MicronautTest
    及扩展设置相关内容委托给
    @132-java-testing-integration-testing
    或对应的
    322
    /
    422
    /
    522
    集成测试技能
  • 契约相关:将OpenAPI文档结构与校验相关内容委托给
    @701-technologies-openapi
  • 强制要求:编辑本仓库中的技能或系统提示XML后,需运行
    ./mvnw clean install -pl skills-generator
    重新生成技能
  • 验证要求:在推广变更前,运行
    ./mvnw clean verify
    mvn clean verify

When to use this skill

何时使用本技能

  • Design or review WireMock stubs (JSON mappings or Java DSL)
  • Improve request matching, isolation, or reset strategy for HTTP mocks
  • Add or fix verification of outbound HTTP calls to a WireMock server
  • Debug flaky tests involving WireMock or unmatched request journals
  • Stub external HTTP APIs in tests with stable fixtures and dynamic ports
  • 设计或评审WireMock存根(JSON映射或Java DSL)
  • 改进HTTP模拟的请求匹配、隔离或重置策略
  • 添加或修复对WireMock服务器的出站HTTP调用验证
  • 调试涉及WireMock或未匹配请求日志的不稳定测试
  • 使用稳定的fixture和动态端口在测试中存根外部HTTP API

Reference

参考资料

For detailed guidance, examples, and constraints, see references/702-technologies-wiremock.md.
如需详细指南、示例及约束条件,请查看references/702-technologies-wiremock.md