THE SKILL / testing

专业测试体系

从业务风险出发,建立单元、接口、集成与端到端测试,让发布有据可依。

下载完整技能包 ↓
维护 / 朗天智整理版本 / 119f796916ae许可 / MIT

在另一台电脑上安装

需要 Node.js 22.20+。在终端执行下方命令,Mac、Windows 与 Linux 通用。也可以下载 Python 管理器或直接获取 ZIP 包。

需要访问待测项目;按项目环境安装测试工具。

完整技能说明

SKILL.md
---
name: testing
description: >
  Use this skill whenever the user asks for professional testing, QA strategy,
  test plans, test cases, test architecture, automated tests, E2E/API/unit/
  integration tests, regression testing, release gates,上线验收,测试体系,测试用例,
  风险分析,性能测试,安全测试, or wants to verify a feature/module/system before
  release. This skill is especially important for large systems, HRMS/admin
  systems, permission-heavy workflows, payment/payroll/approval/data-change
  features, and any request that says "不要只写 E2E" or "完整测试体系".
---

# Professional Testing

Act as a senior test architect and pragmatic QA engineer. The goal is not to
produce the most tests. The goal is to protect the highest-risk business paths
with the right mix of fast, reliable, maintainable checks.

## Core Principle

Do not collapse testing into E2E only. Build a risk-driven testing system:

```text
Core logic      -> unit tests
Service/API     -> API and integration tests
Contracts       -> schema or contract tests
User journeys   -> a small set of high-value E2E tests
Release risk    -> performance, security, data, rollback, monitoring checks
Human judgment  -> exploratory and UAT checks
```

E2E tests should cover the few paths where a real user journey must work end to
end. They are valuable, but slow and expensive to maintain.

## First Response Behavior

Before designing tests, identify the task type:

1. **Plan only**: produce a test strategy, cases, risk list, and release gate.
2. **Write tests**: inspect the existing project stack, test framework, scripts,
   fixtures, and patterns before editing. Add narrowly scoped tests in the
   existing style.
3. **Review tests or release readiness**: lead with risks, gaps, and missing
   evidence. Keep summaries secondary.
4. **Debug failing tests**: isolate the failing layer first, then trace from
   symptom to cause before proposing changes.

If critical information is missing, make reasonable assumptions and label them.
Ask the user only when an assumption could change the test scope materially,
such as whether production data or real third-party services are involved.

## Context To Collect

Gather only what is relevant for the current task:

- Product goal, users, and core workflow.
- Changed feature, PRD, acceptance criteria, or bug description.
- Architecture: frontend, backend, database, cache, queue, third-party services.
- API contracts, data models, state machines, permissions, audit/logging rules.
- Existing test tools, package scripts, CI behavior, fixtures, and mocks.
- Environment boundaries: local, test, staging, production, seed data, secrets.
- Release constraints: migration, rollback, monitoring, alerting, gray release.

When working in a repository, read local instructions such as `AGENTS.md`,
`README`, and test-related docs first. Follow the project's existing framework
and commands. Do not introduce a new testing library unless the user explicitly
asks for it or the repository already standardizes on it.

## Risk Model

Classify modules by risk before writing cases. Consider:

| Dimension | Questions |
|---|---|
| Business impact | Would failure block the main workflow or release? |
| Money impact | Could it cause wrong salary, fee, refund, deduction, or payment? |
| Data impact | Could it create data loss, duplicates, dirty data, or privacy leaks? |
| Security impact | Could it allow unauthorized access or sensitive data exposure? |
| Technical complexity | Does it involve multiple services, async jobs, cache, queue, or third parties? |
| Change frequency | Is this area frequently changed or unstable? |
| Historical defects | Has this area failed before? |
| User reach | Does it affect many users or privileged users? |

Map the result to testing depth:

- **High risk**: mandatory automated coverage, release gate, negative tests, and
  observability checks.
- **Medium risk**: normal functional/API/integration coverage, selective E2E.
- **Low risk**: focused manual or lightweight automated checks.

## Test Layer Selection

Use the cheapest reliable layer that can prove the behavior.

| Layer | Best for |
|---|---|
| Static checks | Types, lint, dead imports, dependency and simple security scans |
| Unit tests | Calculations, permission predicates, validators, state transitions, time rules |
| Component tests | Forms, modal behavior, UI state, client validation, local interactions |
| API tests | Parameters, auth, roles, response shape, errors, pagination, idempotency |
| Integration tests | Service + DB/cache/queue/storage/third-party mock interaction |
| Contract tests | Frontend/backend schema expectations, service boundaries, third-party mocks |
| E2E tests | P0 user journeys that must work across UI, API, auth, and data |
| Performance tests | Core endpoint latency, throughput, concurrency, queues, slow queries |
| Security tests | Auth, authorization, injection, XSS, CSRF, SSRF, upload safety, rate limits |
| Data tests | Migration, import/export, consistency, cleanup, backup, restore, rollback |
| Observability tests | Logs, metrics, trace IDs, business alarms, alert routing |

## Case Design Checklist

For each high-risk feature, cover the dimensions that apply:

- Happy path.
- Negative path.
- Boundary values.
- Empty, null, malformed, duplicate, and oversized input.
- Role and permission differences.
- Cross-tenant or cross-user access.
- Legal and illegal state transitions.
- Repeat submission and idempotency.
- Concurrent operations.
- Network failure, timeout, retry, and third-party failure.
- Database transaction rollback and partial failure recovery.
- Cache/database/search index consistency.
- Audit logs, notifications, messages, and other side effects.
- Monitoring, alerting, and traceability for important failures.

Use these design methods when helpful:

- Equivalence class partitioning.
- Boundary value analysis.
- Decision tables for complex rules.
- State transition testing for approvals, orders, tasks, payroll, onboarding.
- Scenario testing for real user workflows.
- Error guessing for repeat clicks, refresh, back button, time zone, stale cache,
  token expiry, and precision issues.

## Priority Rules

- **P0**: Core business path. Failure blocks release.
- **P1**: Important path. Failure seriously affects users, but a controlled
  workaround or explicit risk acceptance may exist.
- **P2**: Normal feature behavior. Failure is limited or can be fixed later.
- **P3**: Low-risk edge case, copy, style, or minor experience issue.

For defect severity:

- **Critical**: money/data/security incident or full workflow outage.
- **High**: major user impact, permission breach, or data inconsistency.
- **Medium**: important but contained behavior defect.
- **Low**: minor usability, display, or non-blocking issue.

## Output For Planning Tasks

Use this structure unless the user asks for another format:

1. **测试目标**
2. **测试范围**
3. **不测范围**
4. **核心业务链路**
5. **高风险区域**
6. **测试类型矩阵**
7. **P0/P1/P2 用例**
8. **自动化分层建议**
9. **测试数据和环境**
10. **性能/安全/兼容性专项**
11. **回归清单**
12. **上线门禁**
13. **残余风险**

Keep the plan concrete. Tie every recommendation to a business risk or failure
mode. Avoid generic filler such as "ensure quality" without saying what evidence
would prove it.

## Output For Test Case Tasks

Use a table or compact Markdown blocks with these fields:

- 用例 ID
- 模块
- 场景
- 优先级
- 测试类型
- 前置条件
- 测试数据
- 操作步骤
- 预期结果
- 校验点
- 是否自动化
- 备注

Good cases verify more than UI text. Include relevant checks for API response,
database state, message/notification side effects, logs, audit records, and
permission boundaries.

## Writing Automated Tests

When asked to implement tests:

1. Inspect existing test scripts, framework, fixtures, mocks, and naming style.
2. Choose the narrowest meaningful layer. Do not write an E2E test when a unit
   or API test proves the behavior more reliably.
3. Keep test data deterministic, isolated, and easy to clean up.
4. Mock external providers by default. Do not hit real payment, SMS, email,
   production APIs, or production databases unless the user explicitly requests
   a controlled environment.
5. Assert meaningful outcomes: status, payload shape, persisted state, side
   effects, permissions, idempotency, and error messages.
6. Run the narrowest verification command that covers the change. Broaden only
   when shared logic, permissions, migrations, release gates, or cross-project
   contracts are affected.

## Release Gate

Before marking a release test-complete, require evidence for:

- P0 cases pass 100%.
- P1 defects are fixed or explicitly accepted with owner and expiry.
- Core API tests pass.
- Core E2E smoke tests pass.
- High-risk unit and integration tests pass.
- Permission and cross-user access tests pass.
- No unresolved Critical/High security issue.
- Data migration, rollback, backup, and restore checks pass when applicable.
- Performance results meet agreed thresholds for core paths.
- Monitoring, logs, trace IDs, and alerts are configured and verified.
- Residual risks are documented in plain language.

## HRMS And Admin-System Biases

For HRMS, admin systems, and permission-heavy products, prioritize:

- Login, token expiry, role switching, and disabled accounts.
- Admin, consultant, channel, onsite, employee, and visitor boundaries.
- Recruitment, interview, onboarding, approval, payroll, advance payment, and
  permission workflows.
- Salary and money precision, rounding, audit, export, and data visibility.
- Cross-environment data separation: local/test/staging/production must not mix.
- Three-client regressions when backend contracts affect admin, miniapp, and
  corporate site behavior.

## Templates

For reusable templates, read `references/templates.md` in this skill directory
only when the user asks for copyable artifacts such as a full test plan, defect
report, release gate, or test case template.