Agent skill
testing-guide
Testing pyramid and test writing standards for UT/IT/ST/E2E. Use when: writing tests, discussing test coverage, test strategy, or test naming. Keywords: test, unit, integration, e2e, coverage, mock, 測試, 單元, 整合, 端對端.
Install this agent skill to your Project
npx add-skill https://github.com/AsiaOstrich/universal-dev-skills/tree/main/skills/testing-guide
SKILL.md
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:
- Testing Pyramid
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-dev-standards
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
ai-collaboration-standards
Prevent AI hallucination and ensure evidence-based responses when analyzing code or making suggestions. Use when: analyzing code, making recommendations, providing options, or when user asks about confidence/certainty. Keywords: certainty, assumption, inference, evidence, source, 確定性, 推測, 假設, 來源, 證據.
release-standards
Semantic versioning and changelog formatting for software releases. Use when: preparing releases, updating version numbers, writing changelogs. Keywords: version, release, changelog, semver, major, minor, patch, 版本, 發布, 變更日誌.
requirement-assistant
Guide requirement writing, user story creation, and feature specification. Use when: writing requirements, user stories, issues, feature planning. Keywords: requirement, user story, issue, feature, specification, 需求, 功能規劃, 規格.
documentation-guide
Guide documentation structure, README content, and project documentation best practices. Use when: creating README, documentation, docs folder, project setup. Keywords: README, docs, documentation, CONTRIBUTING, CHANGELOG, 文件, 說明文件.
commit-standards
Format commit messages following conventional commits standard. Use when: writing commit messages, git commit, reviewing commit history. Keywords: commit, git, message, conventional, 提交, 訊息, feat, fix, refactor.
git-workflow-guide
Guide Git branching strategies, branch naming, and merge operations. Use when: creating branches, merging, pull requests, Git workflow questions. Keywords: branch, merge, PR, pull request, GitFlow, GitHub Flow, 分支, 合併, 工作流程.
Didn't find tool you were looking for?