用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill testing-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | testing-patterns |
| description | Testing: TDD workflow, Test selection strategy, Mock strategy, When to test what. |
| triggers | {"extensions":[".test.ts",".spec.ts",".test.tsx",".spec.tsx"],"directories":["__tests__/","e2e/","test/"],"keywords":["test","vitest","jest","playwright","coverage","mock","fixture","assertion"]} |
| auto_load_when | Writing tests or test infrastructure |
| agent | qa-specialist |
| tools | ["Read","Write","Bash"] |
Tools: Vitest, RTL, Playwright | Focus: TDD, coverage, mocking
Red-Green-Refactor:
1. Write failing test (describe expected behavior)
2. Write minimal code to pass
3. Refactor (improve without breaking)
When to write tests:
├── Before code (TDD) - preferred for new features
├── After code (debugging) - for fixing bugs
└── Before refactoring - ensure behavior preserved
Test-first benefits:
What to test:
├── Business logic - core functionality
├── User interactions - forms, buttons
├── Edge cases - empty, null, max values
├── Error states - network failure, validation
└── Critical paths - checkout, login
What NOT to test:
├── Implementation details - can change
├── Third-party code - assume works
├── Simple getters/setters - no logic
└── Generated code - no logic
Coverage target:
Unit tests:
├── Test single function/method
├── Mock all external dependencies
├── Fast, isolated
└── Use for: utilities, helpers, algorithms
Integration tests:
├── Test multiple units together
├── Real DB or test DB
├── Use for: API endpoints, DB operations
└── Slower, more realistic
E2E tests:
├── Test full user flow
├── Real browser
├── Use for: critical paths only (login, checkout)
└── Slowest, most realistic
When to mock:
├── External services (API, DB)
├── Slow operations (network, file I/O)
├── Hard to reproduce (timeouts, errors)
└── Third-party libraries
When NOT to mock:
├── Business logic - test real implementation
├── Simple functions - just test directly
├── What you're testing - test real, mock dependencies
Mock location:
AAA Pattern (Arrange-Act-Assert):
├── Arrange: set up data, mocks
├── Act: call function/method
└── Assert: check expected behavior
Test organization:
├── Describe: feature/component being tested
├── It: specific behavior
├── Before/after: setup/teardown
└── Each: per-test setup
What to test:
├── User interactions: clicks, forms, navigation
├── Conditional rendering: states, errors, loading
├── Props: different inputs, different outputs
└── Accessibility: keyboard, screen reader
What NOT to test:
├── Implementation details (state, refs)
├── Styles (except functional)
└── Child components (test them separately)
Testing Library approach:
When to write E2E:
├── Critical user flows
├── Multi-page interactions
└── Browser-specific behavior
What to test:
├── Login → dashboard
├── Add to cart → checkout → confirmation
├── Search → filter → results
└── Error recovery flows
What NOT to test:
├── Every page
├── Edge cases (unit tests cover)
├── Performance (separate suite)
└── Visual details (visual regression tests)
❌ Testing implementation details (internals, private methods)
✅ Test behavior from the user's perspective — what it does, not how
❌ Mocking everything, including the thing under test
✅ Mock only external boundaries (DB, HTTP, clock); test real logic
❌ Single test file with 200 test cases — slow, hard to navigate
✅ Co-locate tests with feature; one file per module
❌ Tests that pass individually but fail in CI (global state leak)
✅ Reset all shared state in beforeEach/afterEach
❌ 0% E2E tests relying only on unit tests
✅ Testing trophy: many unit, some integration, few critical E2E
| Test type | Tool | What to test |
|---|---|---|
| Unit | Vitest / Jest | Pure functions, hooks |
| Component | Testing Library | User interactions |
| Integration | Supertest | API routes |
| E2E | Playwright | Critical user journeys |
| Visual | Chromatic | UI regression |
| Performance | Lighthouse CI | CWV thresholds |