mock-strategy-guide
使用 trait 模式构建 Rust 测试 Mock
当 Rust 测试依赖数据库、HTTP 服务或真实基础设施时,往往会变慢或变得脆弱。此技能帮助 Claude、Codex 和 Claude Code 设计基于 trait 的 mock、可控失败以及 fixture 辅助函数。
使用我的智能体安装
将此请求复制给你的智能体,其中包含权威 Skill 页面和清单。
Review the Skillstore skill "mock-strategy-guide" from https://skillstore.io/skills/emillindfors-mock-strategy-guide.md and its manifest at https://skillstore.io/api/skills/emillindfors-mock-strategy-guide/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.你的智能体仍应展示其计划,并按安全策略请求必要确认。
Agent 可读资源
当 AI Agent、爬虫或脚本需要干净上下文,而不是读取完整页面时,请使用这些链接。
测试它
正在使用“mock-strategy-guide”。 我需要测试一个从 repository 读取用户的服务。
预期结果:
该技能会建议使用由 trait 支持的 mock repository、预置的测试用户,以及围绕成功和用户缺失路径的断言。
正在使用“mock-strategy-guide”。 我需要验证注册流程会发送欢迎邮件。
预期结果:
该技能会推荐一个记录已发送消息的 mock 电子邮件服务,然后检查收件人数量和主题意图。
正在使用“mock-strategy-guide”。 我的单元测试依赖真实数据库。
预期结果:
该技能会建议提取 repository trait,并在单元测试中用内存中实现替换数据库。
安全审计
安全All external command findings are false positives caused by Markdown code fences around Rust test examples, not shell or Ruby execution. The obfuscation heuristic is also a false positive; the file contains plain YAML front matter and Rust-oriented documentation. No prompt injection or malicious semantic intent was found.
风险因素
分享与引用此报告
分享版本化评估报告、中性徽章、嵌入卡片和引用。Skillstore 只报告证据,不判断该 Skill 是否安全。
复制报告链接
https://skillstore.io/skills/emillindfors-mock-strategy-guide/audits/4?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdown 徽章
[](https://skillstore.io/skills/emillindfors-mock-strategy-guide?utm_source=security_passport_badge)HTML 徽章
<a href="https://skillstore.io/skills/emillindfors-mock-strategy-guide?utm_source=security_passport_badge"><img src="https://skillstore.io/badges/skills/emillindfors-mock-strategy-guide/security.svg" alt="Skillstore security assessment" loading="lazy"></a>嵌入卡片
<iframe src="https://skillstore.io/embed/skills/emillindfors-mock-strategy-guide.html" title="Skillstore Security Assessment" sandbox="allow-popups allow-popups-to-escape-sandbox" loading="lazy" referrerpolicy="no-referrer" width="420" height="180"></iframe>学术引用 (APA · BibTeX · CFF)
APA 引用
EmilLindfors. (2026). mock-strategy-guide security audit report (audit version 4) [Author version 1.0.0]. Skillstore. https://skillstore.io/skills/emillindfors-mock-strategy-guide/audits/4BibTeX 引用
@techreport{emillindfors-emillindfors-mock-strategy-guide-2026,
author = {EmilLindfors},
title = {mock-strategy-guide security audit report (audit version 4)},
institution = {Skillstore},
year = {2026},
number = {4},
url = {https://skillstore.io/skills/emillindfors-mock-strategy-guide/audits/4},
note = {Author version 1.0.0}
}CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "mock-strategy-guide security audit report (audit version 4)"
version: "1.0.0"
type: report
authors:
- name: "EmilLindfors"
date-released: "2026-07-06"
url: "https://skillstore.io/skills/emillindfors-mock-strategy-guide/audits/4"
identifiers:
- type: other
value: "skillstore:emillindfors-mock-strategy-guide:audit:4"
description: "Skillstore immutable audit report identifier"
Skillstore 评分
评分依据 证据置信度: 高你能构建什么
Mock 一个 Repository
为依赖已存储用户数据的 Rust 服务设计一个轻量级 repository mock。
验证副作用
捕获对电子邮件或通知服务的调用,并断言该服务的行为正确。
从测试中移除基础设施
使用 trait 抽象和内存中测试实现替换数据库或 HTTP 依赖。
试试这些提示
帮助我为基于 trait 的 repository 创建一个简单 Rust mock。解释其结构和测试流程。
展示如何设计一个会记录调用的 mock 服务,以便我的 Rust 测试可以验证副作用。
设计一种 Rust mock 策略,可以为服务测试返回 success、not-found 和 database-error 结果。
审查这个 Rust 服务设计,并为可维护测试建议 trait 边界、mock 实现和 fixture 辅助函数。
最佳实践
- 让 mock 保持小而局部,只覆盖被测行为。
- 显式建模预期失败,以便测试检查错误处理。
- 为共享数据使用 fixture 辅助函数,但将断言保留在测试主体中。
避免
- 在单元测试中使用生产数据库或 HTTP 服务。
- 将服务逻辑直接耦合到具体基础设施客户端。
- 编写会隐藏重要错误或接受所有输入的 mock。
常见问题
此技能能帮助解决什么问题?
它会执行测试命令吗?
它需要 mocking 框架吗?
它能帮助处理异步 Rust 测试吗?
Claude、Codex 或 Claude Code 可以使用它吗?
什么时候应该避免这种模式?
开发者详情
作者
EmilLindfors许可证
MIT
作者版本
v1.0.0
Skillstore 修订
r1
引用
a06681402992ceae98ba04d54cfd4ab004862696
维护新鲜度
2026/7/18
使用量
4 次下载 · 136 次浏览
文件结构
📄 SKILL.md