qa/unit-testing

qa/unit-testing is a skill for Claude Code from echoVic/boss-skill. It costs 50 tokens per session (5,326 once invoked), scanned A, original, MIT.

A unit-testing guide explains how to test one small piece of code at a time, such as a function, class, or component, while isolating outside systems.

In plain words
What is it for?
It helps write tests for business rules, validation, formatting, state changes, and frontend component or hook behavior across several programming languages.
Why use it?
It helps catch incorrect logic quickly without relying on a database, network, or other tests. It also covers test doubles, which are controlled stand-ins for external dependencies.

Skill for Claude Code

Written for Claude Code: user-invocable in frontmatter. Also seen: agent in frontmatter.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is jest.mock('../repo', () => ({.

Part of the boss plugin — 39 skills, 10 commands, 9 agents, 8 hooks shipped together

Good fit It helps write tests for business rules, validation, formatting, state changes, and frontend component or hook behavior across several programming languages.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/echoVic/boss-skill
agentmods
npx agentmods add skills/echovic/boss-skill/unit-testing

Made for: Claude Code.

Or install boss, the plugin that ships this one along with the rest of its 39 skills, 10 commands, 9 agents, 8 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for qa/unit-testing

README.md
[![agentmods](https://agentmods.dev/badge/skills/echovic/boss-skill/unit-testing/github.svg)](https://agentmods.dev/skills/echovic/boss-skill/unit-testing)
Your own site
<a href="https://agentmods.dev/skills/echovic/boss-skill/unit-testing"><img src="https://agentmods.dev/badge/skills/echovic/boss-skill/unit-testing/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for qa/unit-testing

Your own site · 80×15
<a href="https://agentmods.dev/skills/echovic/boss-skill/unit-testing"><img src="https://agentmods.dev/badge/skills/echovic/boss-skill/unit-testing.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 50 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,326 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00050 $0.05326
Opus 5.5 $0.00020 $0.02130
Sonnet 5.5 $0.00010 $0.01065
Haiku 4.5 $0.00005 $0.00533

Measured 5d ago against content hash e065385b074b, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

qa/unit-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 5d 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.

skill/skills/qa/unit-testing/SKILL.md · 714 lines

How it starts

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

单元测试方法论

单元测试的定义与原则

单元测试验证最小可测试单元(函数、方法、类、组件)的行为,隔离外部依赖。

核心原则

原则 说明
隔离 一个测试只验证一个行为,不依赖其他测试或外部系统
快速 毫秒级执行,全部单元测试应在秒级完成
确定 相同输入多次运行结果一致,不依赖时间/网络/随机数
可读 测试代码即文档,命名清晰表达意图
独立 测试顺序不影响结果,可任意顺序执行

什么该做单元测试

应该测 不应该测
纯函数 / 工具函数 框架内部行为(React 渲染机制)
Service 层业务逻辑 第三方库本身
组件渲染与交互(前端) 配置文件 / 常量
Hook 状态逻辑 简单的 getter/setter
校验 / 转换 / 格式化逻辑 数据库查询(属于集成测试)
状态机 / 状态转换 网络请求(属于集成测试)

AAA 模式(Arrange-Act-Assert)

每个单元测试遵循三段式结构:

it('applies 10% discount when total > 100', () => {
  // Arrange — 准备测试数据和环境
  const items = [{ price: 60, quantity: 2 }]; // total = 120
  const discount = 0.1;

  // Act — 执行被测逻辑
  const result = calculateTotal(items, discount);

  // Assert — 验证结果
  expect(result).toBe(108); // 120 * 0.9
});

命名规范:[期望行为] when [条件] 或 [动作] [结果]

// ✅ 好
it('returns error when email is invalid');
it('calculates total with discount applied');

// ❌ 差
it('should work');
it('test1');

Test Doubles(测试替身)

根据用途选择不同的替身类型:

类型 用途 示例
Dummy 占位,不被调用 传一个空对象满足参数签名
Stub 提供预设返回值 repo.findById.mockResolvedValue(user)
Spy 记录调用信息 expect(fn).toHaveBeenCalledWith(arg)
Mock Stub + Spy,验证交互 mock.calledWith(...)
Fake 简化的真实实现 内存数据库替代真实 DB

何时使用哪种

// Stub:被测代码需要依赖返回值,但不关心调用细节
jest.mock('../repo', () => ({
  findById: jest.fn().mockResolvedValue({ id: '1', name: 'Alice' }),
}));

// Spy:需要验证依赖是否被正确调用
const emailSpy = jest.spyOn(emailService, 'send');
await userService.register(user);
expect(emailSpy).toHaveBeenCalledWith(user.email, expect.any(String));

// Fake:需要一个可用但简化的实现
class FakeCache implements Cache {
  private store = new Map<string, string>();
  async get(k: string) {
    return this.store.get(k) ?? null;
  }
  async set(k: string, v: string) {
    this.store.set(k, v);
  }
}

Read the full file on GitHub · 714 lines

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. 5d ago First seen · 714 lines · 50 tokens per session scan A e065385b074b

Subscribe to this mod's changes

qa/unit-testing is a skill published in the GitHub repository echoVic/boss-skill (544 stars, last pushed yesterday), licensed MIT. It adds 50 tokens to every session and 5,326 once invoked, about $0.0002 per session on Opus 5.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-10-28.