放心

其他 社区

技能解读

当前原文的自动摘译,尚未人工审校。

何时不使用此技能

单元测试 - 使用 junit 与 Mockito 进行隔离测试 E2E 浏览器测试 - 使用 Selenium 或 Playwright WebSocket 测试 - 使用专用的 WebSocket 测试工具 非 Java 项目 - 使用特定于语言的 HTTP 客户端 GraphQL API - 考虑特定于 GraphQL 的测试工具

汉克雷斯特匹配者科穆尼

匹配器 · Uso equalTo(value) · 精确匹配 notNullValue() · 非空 hasSize(n) · 集合大小 containsString(str) · 字符串包含

反模式

反模式 · 为什么不好 · 解决方案 硬编码基本 URI · 不可跨环境移植 · 使用 RestAssured.baseURI 或配置 不设置 contentType · 请求可能会失败或被误解 · 始终为 POST/PUT 设置 contentType 忽略状态代码 · 无提示失败 · 始终断言状态代码 不使用路径参数 · 难以阅读,容易出错 · 使用 {id} 占位符

快速故障排除

问题 · 可能的原因 · 解决方案 “连接被拒绝” · 服务器未运行 · 启动服务器,验证端口“预期状态 200,但实际为 500” · API 错误或错误请求 · 检查服务器日志,验证请求正文“无法反序列化 JSON” · 内容类型或正文格式错误 · 验证 Content-Type 标头,检查 JSON 身份验证失败 · 令牌缺失/错误 · 检查授权标头

参考文档

REST Assured 文档来源:claude-dev-suite/claude-dev-suite — 由 TomeVault 分发。

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
通用
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@tomevault-io · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
未声明(默认跨平台)
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md
# REST Assured - Quick Reference

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `rest-assured` for comprehensive documentation.

## When NOT to Use This Skill

- **Unit Tests** - Use `junit` with Mockito for isolated tests
- **E2E Browser Tests** - Use Selenium or Playwright
- **WebSocket Testing** - Use dedicated WebSocket testing tools
- **Non-Java Projects** - Use language-specific HTTP clients
- **GraphQL APIs** - Consider GraphQL-specific testing tools

## Pattern Essenziali

### GET Request
```java
given()
    .baseUri("http://localhost:8080")
    .contentType("application/json")
.when()
    .get("/api/v1/users/1")
.then()
    .statusCode(200)
    .body("name", equalTo("John"));
```

### POST Request
```java
given()
    .contentType("application/json")
    .body("""
        {"name": "John", "email": "john@example.com"}
        """)
.when()
    .post("/api/v1/users")
.then()
    .statusCode(201)
    .body("id", notNullValue());
```

### Spring Boot Integration
```java
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class UserApiTest {
    @LocalServerPort
    private int port;

    @BeforeEach
    void setUp() {
        RestAssured.port = port;
    }

    @Test
    void shouldGetUsers() {
        given()
        .when().get("/api/v1/users")
        .then().statusCode(200);
    }
}
```

### Authentication
```java
// Bearer Token
given().header("Authorization", "Bearer " + token)

// Basic Auth
given().auth().basic("user", "pass")
```

## Hamcrest Matchers Comuni
| Matcher | Uso |
|---------|-----|
| `equalTo(value)` | Exact match |
| `notNullValue()` | Not null |
| `hasSize(n)` | Collection size |
| `containsString(str)` | String contains |

## Anti-Patterns

| Anti-Pattern | Why It's Bad | Solution |
|--------------|--------------|----------|
| Hardcoding base URI | Not portable across environments | Use RestAssured.baseURI or config |
| Not setting contentType | Request may fail or be misinterpreted | Always set contentType for POST/PUT |
| Ignoring status codes | Silent failures | Always assert status code |
| Not using path parameters | Hard to read, error-prone | Use {id} placeholders |
| Testing too much in one test | Hard to debug | One endpoint/scenario per test |
| No authentication testing | Security gaps | Test auth headers, tokens |
| Not validating response schema | API contract violations | Use JSON schema validation |

## Quick Troubleshooting

| Problem | Likely Cause | Solution |
|---------|--------------|----------|
| "Connection refused" | Server not running | Start server, verify port |
| "Expected status 200 but was 500" | API error or wrong request | Check server logs, validate request body |
| "Cannot deserialize JSON" | Wrong content type or body format | Verify Content-Type header, check JSON |
| Authentication fails | Missing/wrong token | Check Authorization header |
| Timeout | Slow API or network issue | Increase timeout or investigate performance |
| "Path not found" | Wrong URL or method | Verify endpoint exists, check HTTP method |

## Reference Documentation
- [REST Assured Docs](https://rest-assured.io/)

---
> Source: [claude-dev-suite/claude-dev-suite](https://github.com/claude-dev-suite/claude-dev-suite) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。