testing-guide
关于
This skill provides testing pyramid standards and best practices for systematic testing across unit, integration, system, and end-to-end levels. Use it when writing tests, discussing coverage, or defining test strategy to implement proper testing proportions and naming conventions. It offers quick reference guides and actionable standards for developers implementing a structured testing approach.
快速安装
Claude Code
推荐/plugin add https://github.com/AsiaOstrich/universal-dev-skillsgit clone https://github.com/AsiaOstrich/universal-dev-skills.git ~/.claude/skills/testing-guide在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Testing Guide
This skill provides testing pyramid standards and best practices for systematic testing.
Quick Reference
Testing Pyramid
┌─────────┐
│ E2E │ ← Fewer, slower (3%)
─┴─────────┴─
┌─────────────┐
│ ST │ ← System (7%)
─┴─────────────┴─
┌─────────────────┐
│ IT │ ← Integration (20%)
─┴─────────────────┴─
┌─────────────────────┐
│ UT │ ← Unit (70%)
└─────────────────────┘
Test Levels Overview
| Level | Scope | Speed | Dependencies |
|---|---|---|---|
| UT | Single function/class | < 100ms | Mocked |
| IT | Component interaction | 1-10s | Real DB (containerized) |
| ST | Full system | Minutes | Production-like |
| E2E | User journeys | 30s+ | Everything real |
Coverage Targets
| Metric | Minimum | Recommended |
|---|---|---|
| Line | 70% | 85% |
| Branch | 60% | 80% |
| Function | 80% | 90% |
Detailed Guidelines
For complete standards, see:
Naming Conventions
File Naming
[ClassName]Tests.cs # C#
[ClassName].test.ts # TypeScript
[class_name]_test.py # Python
[class_name]_test.go # Go
Method Naming
[MethodName]_[Scenario]_[ExpectedResult]()
should_[behavior]_when_[condition]()
test_[method]_[scenario]_[expected]()
Test Doubles
| Type | Purpose | When to Use |
|---|---|---|
| Stub | Returns predefined values | Fixed API responses |
| Mock | Verifies interactions | Check method called |
| Fake | Simplified implementation | In-memory database |
| Spy | Records calls, delegates | Partial mocking |
When to Use What
- UT: Use mocks/stubs for all external deps
- IT: Use fakes for DB, stubs for external APIs
- ST: Real components, fake only external services
- E2E: Real everything
AAA Pattern
test('method_scenario_expected', () => {
// Arrange - Setup test data
const input = createTestInput();
const sut = new SystemUnderTest();
// Act - Execute behavior
const result = sut.execute(input);
// Assert - Verify result
expect(result).toBe(expected);
});
FIRST Principles
- Fast - Tests run quickly
- Independent - Tests don't affect each other
- Repeatable - Same result every time
- Self-validating - Clear pass/fail
- Timely - Written with production code
Anti-Patterns to Avoid
- ❌ Test Interdependence (tests must run in order)
- ❌ Flaky Tests (sometimes pass, sometimes fail)
- ❌ Testing Implementation Details
- ❌ Over-Mocking
- ❌ Missing Assertions
- ❌ Magic Numbers/Strings
Configuration Detection
This skill supports project-specific configuration.
Detection Order
- Check
CONTRIBUTING.mdfor "Disabled Skills" section- If this skill is listed, it is disabled for this project
- Check
CONTRIBUTING.mdfor "Testing Standards" section - If not found, default to standard coverage targets
First-Time Setup
If no configuration found and context is unclear:
- Ask the user: "This project hasn't configured testing standards. Would you like to customize coverage targets?"
- After user selection, suggest documenting in
CONTRIBUTING.md:
## Testing Standards
### Coverage Targets
| Metric | Target |
|--------|--------|
| Line | 80% |
| Branch | 70% |
| Function | 85% |
Configuration Example
In project's CONTRIBUTING.md:
## Testing Standards
### Coverage Targets
| Metric | Target |
|--------|--------|
| Line | 80% |
| Branch | 70% |
| Function | 85% |
### Testing Framework
- Unit Tests: Jest
- Integration Tests: Supertest
- E2E Tests: Playwright
License: CC BY 4.0 | Source: universal-doc-standards
GitHub 仓库
相关推荐技能
content-collections
元Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
creating-opencode-plugins
元该Skill为开发者创建OpenCode插件提供指导,涵盖命令、文件、LSP等25+种事件类型。它详细说明了插件结构、事件API规范及JavaScript/TypeScript实现模式,帮助开发者构建事件驱动的模块。适用于需要拦截操作、扩展功能或自定义AI助手行为的插件开发场景。
evaluating-llms-harness
测试该Skill通过60+个学术基准测试(如MMLU、GSM8K等)评估大语言模型质量,适用于模型对比、学术研究及训练进度追踪。它支持HuggingFace、vLLM和API接口,被EleutherAI等行业领先机构广泛采用。开发者可通过简单命令行快速对模型进行多任务批量评估。
langchain
元LangChain是一个用于构建LLM应用程序的框架,支持智能体、链和RAG应用开发。它提供多模型提供商支持、500+工具集成、记忆管理和向量检索等核心功能。开发者可用它快速构建聊天机器人、问答系统和自主代理,适用于从原型验证到生产部署的全流程。
