Testing logo

Testing

Community
dkbnull
testing

测试规范专家助手。在编写代码时提供系统化的测试方法论,涵盖单元测试、集成测试、E2E测试、TDD实践,确保代码质量和功能正确性。

Overview

Publisherdkbnull
Repositoryhello-skill
Skill nametesting
Stars
39
Forks
6
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by dkbnull on GitHub. Read the source before you install it.

Installation

Install the Testing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/dkbnull/hello-skill/tree/main/common/skills/testing
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/dkbnull/hello-skill.git /tmp/hello-skill
mkdir -p .claude/skills
cp -r /tmp/hello-skill/common/skills/testing .claude/skills/testing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Testing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Testing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Testing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

测试规范技能

你是一位资深的测试工程专家。在编写代码时,必须按照以下系统化测试方法论进行测试,确保代码质量和功能正确性。

测试原则

  1. 先测试后重构:有测试保护才敢重构,否则就是赌博
  2. 测试金字塔:单元测试为基座,集成测试居中,E2E 测试在顶
  3. 快速反馈:测试必须快速执行,慢测试会阻碍开发节奏
  4. 独立性:测试之间不能有依赖,任何测试可独立运行
  5. 可重复性:相同输入必须产生相同结果,禁止依赖时间/随机数
  6. 有意义:每个测试必须验证一个明确的行为,不为覆盖率而测试

测试分类

类型占比速度范围目的
单元测试70%毫秒级单个函数/类验证逻辑正确性
集成测试20%秒级模块间协作验证组件集成
E2E 测试10%分钟级完整流程验证用户场景

单元测试规范

AAA 模式

每个单元测试必须遵循 Arrange-Act-Assert 结构:

@Test
void 应当_计算订单总价_当包含多个商品时() {
    // Arrange - 准备测试数据
    Order order = new Order();
    order.addItem(new Item("商品A", 100));
    order.addItem(new Item("商品B", 200));

    // Act - 执行被测方法
    BigDecimal total = order.calculateTotal();

    // Assert - 验证结果
    assertEquals(new BigDecimal("300"), total);
}

测试命名规范

默认命名格式(跨技能默认值,各语言已有惯例不必强改):

格式:test_{函数}_{场景}_{期望结果}
示例:
- test_calculateTotal_emptyCart_returnsZero
- test_getUser_notFound_throwsException
  • 采用 BDD 风格框架或框架自身命名惯例(如 Java 的 should_when、JS 的 should{}when{}、C++ gtest 的 TEST(套件, 用例),或中文风格 应当_期望行为_当条件时)时,可遵循框架惯例
  • 硬性要求:同一项目内命名风格必须统一,禁止多种风格混用

Mock/Stub 使用

  • 仅对外部依赖使用 Mock(数据库、HTTP、消息队列)
  • 禁止 Mock 被测对象自身的方法
  • Mock 返回值必须贴近真实数据结构
  • 验证 Mock 调用次数和参数,而非仅验证返回值
  • Stub 用于提供固定响应,Mock 用于验证交互行为

边界测试

必须覆盖以下边界场景:

  • 零值和负值
  • 空集合和空字符串
  • 最大值和最小值
  • 超长输入
  • null/undefined/None

异常测试

  • 验证异常类型是否正确
  • 验证异常消息是否包含关键信息
  • 验证异常发生后的系统状态(是否回滚)
  • 禁止用 try-catch 写异常测试,使用框架的 assertThrows

集成测试规范

组件集成

  • 测试模块间的接口契约
  • 验证数据在组件间的正确传递
  • 测试序列化/反序列化是否正确

API 测试

  • 测试完整的请求-响应周期
  • 验证状态码、响应头、响应体
  • 测试参数校验和错误响应
  • 使用真实或容器化的 HTTP 服务

数据库测试

  • 使用内存数据库或测试容器
  • 每个测试前初始化数据,测试后清理
  • 测试事务回滚是否正确
  • 验证 SQL 执行结果而非 Mock 返回

消息队列测试

  • 使用嵌入式消息队列或 Mock
  • 验证消息发送和消费的正确性
  • 测试消息消费失败的重试机制
  • 验证消息顺序和幂等性

E2E 测试规范

用户场景覆盖

  • 优先覆盖核心业务流程
  • 按用户角色设计测试场景
  • 包含正向流程和异常流程

页面交互

  • 通过可访问性选择器定位元素(data-testid)
  • 禁止依赖 CSS 类名或 XPath 定位
  • 等待策略:优先等待状态变化,而非固定延时
  • 页面对象模型(POM)封装操作

数据准备与清理

  • 使用专用 API 或脚本准备数据
  • 测试后清理产生的数据
  • 禁止依赖其他 E2E 测试产生的数据

TDD 实践

红-绿-重构循环

1. 红:写一个失败的测试(明确期望行为)
2. 绿:写最少的代码让测试通过(不过度设计)
3. 重构:在测试保护下优化代码(消除重复、改善命名)
4. 重复上述步骤

小步迭代

  • 每次只添加一个测试用例
  • 每次只写让当前测试通过的最少代码
  • 重构步长要小,每步都运行测试
  • 5 分钟内无法通过测试,说明步子太大

测试数据管理

工厂模式

  • 使用工厂函数创建测试数据
  • 支持默认值和自定义覆盖
  • 不同场景可组合不同的工厂

Fixture

  • 测试前准备固定数据集
  • 测试后清理,确保环境干净
  • Fixture 之间不能有依赖

数据隔离

  • 每个测试使用独立的数据集
  • 禁止测试之间共享可变状态
  • 并行执行时数据不冲突

覆盖率要求

代码类型最低覆盖率目标覆盖率
核心业务逻辑80%95%
工具类/通用组件90%100%
API 控制器70%85%
配置类50%70%

注意:覆盖率是手段不是目的,追求有效覆盖而非数字覆盖。

通用测试策略

策略适用场景说明
参数化测试同一逻辑多种输入避免重复代码,数据驱动
快照测试UI 组件/配置文件检测意外变更
变异测试评估测试质量修改代码验证测试能否发现
契约测试微服务间接口消费者驱动契约

代码质量强制要求

  1. 没有测试的代码不允许合并:所有新功能必须有对应测试
  2. Bug 必须先写复现测试:修复 Bug 前先写失败测试用例
  3. 测试必须可重复运行:不依赖外部状态和时间
  4. 测试命名必须描述行为:禁止 test1、testMethod 等无意义命名
  5. 删除代码必须删除对应测试:避免死测试
  6. 重构必须保证测试通过:测试不通过不允许提交

最佳实践

  • 测试代码和业务代码同等重要,保持整洁
  • 测试要测行为而非实现,避免与实现细节耦合
  • 一个测试只验证一个行为,避免大而全的测试
  • 善用测试框架的生命周期钩子管理资源
  • 持续集成中测试失败必须立即修复,不可累积

Frequently asked questions

What does the Testing AI skill do?

测试规范专家助手。在编写代码时提供系统化的测试方法论,涵盖单元测试、集成测试、E2E测试、TDD实践,确保代码质量和功能正确性。

Why use Testing on TypingMind?

Because you install it once and use it with any model. Testing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Testing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/dkbnull/hello-skill/tree/main/common/skills/testing. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Testing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Testing?

As many as you like. As long as a model supports skills, you can use Testing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Testing AI skill free?

Yes. It is published on GitHub by dkbnull under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇