testing

A guide to writing tests that check what software should do rather than how its code is arranged. Tests are repeatable checks; it covers functions, external services, user interfaces, and cooperating modules.

In plain words
What is it for?
Use it when adding tests for new behavior, repairing fragile or flaky tests, choosing between unit, integration, UI, and end-to-end tests, or deciding what to mock.
Why use it?
It helps catch real bugs without creating tests that break whenever the implementation is refactored. It also explains when to use mocks, which simulate outside systems such as databases or HTTP services.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/lion-1209/coderio/testing
Any agent
npx skills add Lion-1209/coderio --skill testing
Clone the repo
git clone --depth 1 https://github.com/Lion-1209/coderio

Made for: Claude Code, Codex.

Per session 16 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,699 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00016 $0.02699
Opus 5 $0.00008 $0.01350
Sonnet 5 $0.00003 $0.00540
Haiku 4.5 $0.00002 $0.00270

Measured 2d ago against content hash cf1ba0bf5d4a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

testing scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

  • testing — 100% identical, 0 lines differ
src/coderio/skills/lion-skills/skills/testing/SKILL.md · 135 lines

How it starts

The opening of the file, as written. The whole thing — 135 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Testing

概述

写能真正抓住 bug、且不脆弱(改实现不会无端崩)的测试。核心:测试是行为的契约,不是"代码的镜像"——测的是"给它这个输入,该有这个结果",不是"它内部该这样工作"。好测试让你敢改实现(因为测试守着行为),坏测试让你不敢改(因为一改测试就崩)。

何时使用

  • 写完功能,要补测试
  • 写测试时纠结测什么、不测什么、要不要 mock
  • 现有测试脆弱(改实现就一片红)或 flaky(时过时不过)
  • 测试覆盖率挺高但 bug 还是漏

不该用:纯探索/原型(不要求正确,测试是负担);一次性脚本(跑完即弃)。

与相邻 skill 的衔接testing 在 task-breakdown 下游、verify-and-fix 上游——task 拆出"做完 X 能验证 Y",testing 负责把 Y 写成可重复运行的测试,verify-and-fix 负责跑它验证。三者接力:task 定验证目标 → testing 把目标落地成测试 → verify-and-fix 用测试验证完成。

核心内容

先识别被测对象的性质

写测试前先看清"被测的是什么",策略大不相同——这决定了要不要 mock、用什么工具、放哪个层次:

  • 纯函数(无副作用、输入决定输出,如 calculateDiscount)→ 直接输入输出断言,零 mock,单元层。
  • 有外部依赖的逻辑(如调 DB/HTTP 的 service)→ mock 掉外部副作用,验证被测逻辑对依赖返回值的真实处理(详见下文 mock 纪律)。
  • UI 组件(渲染 + 交互)→ 用组件测试库测渲染输出和用户交互,不测内部 state 细节。
  • 模块协作(多个组件配合)→ 集成层,用真实(或内存版)依赖验证组件间契约。

识别性质能避免最常见的错配:给纯函数上 mock、给 UI 组件测 state、把单元能测的逻辑推到端到端。先问"它是什么",再问"怎么测"。

测行为,不测实现

这是测试设计的第一原则。测"做什么",不测"怎么做"

  • 测行为(对):给定输入,断言输出/可观测结果。例:calculateDiscount(100, 'vip') 应返回 80
  • 测实现(错):断言内部走了哪个分支、调了哪个方法几次。例:断言"内部调用了 multiply 两次"。

为什么测实现糟糕:实现是会变的(重构、换算法、优化),但行为不该变。测实现的测试,每次合理的实现改动都会让它崩——这就是脆弱测试。它逼你改实现时还得改测试,让测试从"保护"变成"负担"。

判别尺子:问自己"如果我把内部实现整个换掉(但行为不变),这个测试还该过吗?" 该过 → 测的是行为(对);崩了 → 测的是实现(错,改)。

例外:有些"交互契约"本身就是行为——比如"调支付时确实发了请求""保存时确实写库了"。这类"验证发生了正确的外部交互"是测行为,不是测实现。区分点:你关心的是结果(钱扣了/数据存了),还是调用细节(调了 3 次不是 2 次)。前者是行为,后者是过度断言。

测什么:聚焦有判断的逻辑,跳过无价值的

不是每行代码都值得测。测试有价值,是因为代码有逻辑、可能错。按代码性质分:

  • 有判断的逻辑(分支、计算、状态转换、边界处理)→ 重点测。这是 bug 高发区。
  • 纯数据搬运(getter/setter、直接赋值、简单透传)→ 不值得专门测。测它等于测语言本身。
  • 框架/库的代码 → 不测。你不需要测 ORM 的 save 有没有存数据库,那是框架的事。

判断尺子:这段代码如果写错了,测试能抓住吗?写对了,测试有信息量吗? 两问都否 → 不值得测(如 getter)。把测试预算投到"写错会出事"的地方。

边界和错误路径是重点:happy path 谁都会测,但 bug 大多藏在边界(空值、零、负数、空集合、最大值)和错误路径(异常、超时、依赖失败)。问自己"这个函数在什么输入下会出错?"——那些输入就是要补的测试。

mock 的纪律:隔离依赖,不隔离被测逻辑

mock 用来隔离外部依赖(数据库、网络、第三方服务、时间),让测试快、稳、可重复。但 mock 容易被滥用:

  • 合理 mock:被测代码依赖的外部副作用(真连库太慢、真发邮件会骚扰人)。mock 掉它们,专注测被测逻辑。
  • 过度 mock:把被测对象自己的依赖链也 mock 掉,导致测试退化成"测 mock"——你 mock 了 db.save 返回固定 id,又只断言"调了 save",那其实什么都没测。

Read the full file on GitHub · 135 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 135 lines · 16 tokens per session scan A cf1ba0bf5d4a

Subscribe to this mod's changes

testing is a skill published in the GitHub repository Lion-1209/coderio (9 stars, last pushed 4d ago), licensed MIT. It adds 16 tokens to every session and 2,699 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

blog-writer

Peri 项目博客写作风格指南。当用户说"写博客"、"写文章"、"出稿"、 "按风格写"、"博客"时触发。也适用于用户丢过来素材说"帮我写篇博客"的场景。 覆盖项目介绍、技术复盘、架构讨论、性能优化、架构设计等类型。.

KonghaYao/peri · 90 tokens

auto-devflow

Use when starting an issue, bugfix, feature, or refactor that benefits from an adaptive development workflow. Select lite, normal, pro, max, or ultra from task complexity and risk, then use only the coordination, review, and verification phases that the task actually needs.

KonghaYao/peri · 60 tokens

langfuse

Interact with Langfuse and access its documentation. Use when needing to (1) query or modify Langfuse data programmatically via the CLI — traces, prompts, datasets, scores, sessions, and any other API resource, (2) look up Langfuse documentation, concepts, integration guides, or SDK usage, or (3) understand how any…

KonghaYao/peri · 100 tokens

self-build

Builds isolated npm capability packages that operate on real project code and connects them to Peri through MCP/MCPP and MetaHarness. Use when adding tools, resources, remote skills or agents, creating a Bun/Node.js stdio server, linking .mcp.json, or changing the active prompt and middleware set.

KonghaYao/peri · 66 tokens

project-maturity

对任意项目进行全面的成熟度评估扫描。当用户说"检查项目成熟度"、"项目评估"、 "maturity assessment"、"代码质量扫描"、"项目健康度"、"项目体检"、 "scan project maturity"、"项目有多成熟"时触发。适用场景:接手新项目前的摸底、 发布前的质量审查、技术尽调、团队内部代码健康度盘点。.

KonghaYao/peri · 105 tokens

auto-issue-fixer

Issue 全生命周期管理——从创建到归档。当用户描述技术问题、提 bug、"帮我记录"、 "修一下 X issue"、"验证一下"、"归档 issue"时立即触发。单入口自动分发, 替代旧 issue-create/fix-issue/issue-verify/issue-archive 四个技能。 即使用户没有用"issue"这个词,只要在描述值得追踪的技术问题就应触发。.

KonghaYao/peri · 106 tokens