universal-dev-standards 4.2.0 → 5.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/uds.js +165 -5
- package/bundled/core/acceptance-test-driven-development.md +19 -721
- package/bundled/core/accessibility-standards.md +862 -0
- package/bundled/core/ai-agreement-standards.md +95 -0
- package/bundled/core/ai-friendly-architecture.md +2 -0
- package/bundled/core/ai-instruction-standards.md +2 -0
- package/bundled/core/anti-hallucination.md +90 -637
- package/bundled/core/behavior-driven-development.md +20 -735
- package/bundled/core/changelog-standards.md +4 -0
- package/bundled/core/checkin-standards.md +21 -4
- package/bundled/core/code-review-checklist.md +3 -0
- package/bundled/core/commit-message-guide.md +14 -3
- package/bundled/core/deployment-standards.md +296 -0
- package/bundled/core/developer-memory.md +568 -0
- package/bundled/core/documentation-structure.md +114 -18
- package/bundled/core/documentation-writing-standards.md +272 -2
- package/bundled/core/error-code-standards.md +3 -0
- package/bundled/core/forward-derivation-standards.md +134 -8
- package/bundled/core/git-workflow.md +72 -686
- package/bundled/core/guides/anti-hallucination-guide.md +517 -0
- package/bundled/core/guides/git-workflow-guide.md +954 -0
- package/bundled/core/guides/performance-guide.md +508 -0
- package/bundled/core/guides/refactoring-guide.md +608 -0
- package/bundled/core/guides/security-guide.md +485 -0
- package/bundled/core/logging-standards.md +337 -2
- package/bundled/core/performance-standards.md +231 -0
- package/bundled/core/project-context-memory.md +180 -0
- package/bundled/core/project-structure.md +315 -2
- package/bundled/core/refactoring-standards.md +81 -761
- package/bundled/core/requirement-engineering.md +39 -0
- package/bundled/core/reverse-engineering-standards.md +6 -4
- package/bundled/core/security-standards.md +244 -0
- package/bundled/core/spec-driven-development.md +20 -319
- package/bundled/core/test-completeness-dimensions.md +213 -11
- package/bundled/core/test-driven-development.md +22 -978
- package/bundled/core/testing-standards.md +222 -2903
- package/bundled/core/versioning.md +16 -55
- package/bundled/core/virtual-organization-standards.md +85 -0
- package/bundled/locales/README.md +4 -4
- package/bundled/locales/zh-CN/CHANGELOG.md +18 -18
- package/bundled/locales/zh-CN/CLAUDE.md +3 -3
- package/bundled/locales/zh-CN/MAINTENANCE.md +7 -7
- package/bundled/locales/zh-CN/README.md +2 -2
- package/bundled/locales/zh-CN/STANDARDS-MAPPING.md +1 -1
- package/bundled/locales/zh-CN/adoption/ADOPTION-GUIDE.md +3 -3
- package/bundled/locales/zh-CN/adoption/DAILY-WORKFLOW-GUIDE.md +66 -7
- package/bundled/locales/zh-CN/adoption/STATIC-DYNAMIC-GUIDE.md +22 -22
- package/bundled/locales/zh-CN/adoption/checklists/enterprise.md +5 -5
- package/bundled/locales/zh-CN/adoption/checklists/minimal.md +4 -4
- package/bundled/locales/zh-CN/adoption/checklists/recommended.md +5 -5
- package/bundled/locales/zh-CN/ai/MAINTENANCE.md +13 -13
- package/bundled/locales/zh-CN/core/ai-instruction-standards.md +1 -1
- package/bundled/locales/zh-CN/core/anti-hallucination.md +39 -3
- package/bundled/locales/zh-CN/core/checkin-standards.md +18 -5
- package/bundled/locales/zh-CN/core/commit-message-guide.md +1 -1
- package/bundled/locales/zh-CN/core/developer-memory.md +576 -0
- package/bundled/locales/zh-CN/core/documentation-structure.md +43 -5
- package/bundled/locales/zh-CN/core/documentation-writing-standards.md +146 -5
- package/bundled/locales/zh-CN/core/git-workflow.md +179 -4
- package/bundled/locales/zh-CN/core/logging-standards.md +177 -4
- package/bundled/locales/zh-CN/core/project-structure.md +117 -5
- package/bundled/locales/zh-CN/core/refactoring-standards.md +3 -3
- package/bundled/locales/zh-CN/core/reverse-engineering-standards.md +6 -6
- package/bundled/locales/zh-CN/core/spec-driven-development.md +516 -14
- package/bundled/locales/zh-CN/core/test-completeness-dimensions.md +155 -24
- package/bundled/locales/zh-CN/core/test-driven-development.md +71 -20
- package/bundled/locales/zh-CN/core/testing-standards.md +4 -4
- package/bundled/locales/zh-CN/core/versioning.md +1 -1
- package/bundled/locales/zh-CN/docs/AI-AGENT-ROADMAP.md +90 -51
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +184 -0
- package/bundled/locales/zh-CN/docs/CLI-FLOW.md +239 -0
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +320 -0
- package/bundled/locales/zh-CN/docs/OPERATION-WORKFLOW.md +43 -43
- package/bundled/locales/zh-CN/docs/STANDARDS-REFERENCE.md +440 -0
- package/bundled/locales/zh-CN/docs/USAGE-MODES-COMPARISON.md +1 -1
- package/bundled/locales/zh-CN/docs/WINDOWS-GUIDE.md +1 -1
- package/bundled/locales/zh-CN/integrations/codex/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/gemini-cli/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/github-copilot/README.md +5 -5
- package/bundled/locales/zh-CN/integrations/github-copilot/copilot-instructions.md +9 -9
- package/bundled/locales/zh-CN/integrations/github-copilot/skills-mapping.md +18 -6
- package/bundled/locales/zh-CN/integrations/google-antigravity/README.md +2 -2
- package/bundled/locales/zh-CN/integrations/opencode/README.md +3 -3
- package/bundled/locales/zh-CN/integrations/opencode/skills-mapping.md +22 -10
- package/bundled/locales/zh-CN/integrations/openspec/README.md +1 -1
- package/bundled/locales/zh-CN/integrations/spec-kit/AGENTS.md +3 -3
- package/bundled/locales/zh-CN/integrations/spec-kit/README.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/bilingual.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/english.md +1 -1
- package/bundled/locales/zh-CN/options/commit-message/traditional-chinese.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/gitflow.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/github-flow.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/merge-commit.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/rebase-ff.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/squash-merge.md +1 -1
- package/bundled/locales/zh-CN/options/git-workflow/trunk-based.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/dotnet.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/go.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/java.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/nodejs.md +1 -1
- package/bundled/locales/zh-CN/options/project-structure/python.md +1 -1
- package/bundled/locales/zh-CN/options/testing/e2e-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/integration-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/system-testing.md +1 -1
- package/bundled/locales/zh-CN/options/testing/unit-testing.md +1 -1
- package/bundled/locales/zh-CN/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +2 -2
- package/bundled/locales/zh-CN/skills/README.md +131 -81
- package/bundled/locales/zh-CN/skills/agents/README.md +281 -0
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +10 -10
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +8 -8
- package/bundled/locales/zh-CN/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +8 -8
- package/bundled/locales/zh-CN/skills/ai-friendly-architecture/SKILL.md +221 -0
- package/bundled/locales/zh-CN/skills/ai-instruction-standards/SKILL.md +214 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/SKILL.md +71 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/acceptance-criteria-guide.md +428 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/atdd-workflow.md +484 -0
- package/bundled/locales/zh-CN/skills/atdd-assistant/guide.md +368 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/SKILL.md +68 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/bdd-workflow.md +406 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/gherkin-guide.md +454 -0
- package/bundled/locales/zh-CN/skills/bdd-assistant/guide.md +324 -0
- package/bundled/locales/zh-CN/skills/changelog-guide/SKILL.md +64 -0
- package/bundled/locales/zh-CN/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +6 -7
- package/bundled/locales/zh-CN/skills/checkin-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-CN/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -7
- package/bundled/locales/zh-CN/skills/code-review-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/methodology.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/commands → commands}/refactor.md +3 -3
- package/bundled/locales/zh-CN/skills/commit-standards/SKILL.md +61 -0
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/commit-standards → commit-standards}/language-options.md +3 -3
- package/bundled/locales/zh-CN/skills/docs-generator/SKILL.md +59 -0
- package/bundled/locales/zh-CN/skills/docs-generator/guide.md +262 -0
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -8
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/forward-derivation/SKILL.md +62 -0
- package/bundled/locales/zh-CN/skills/forward-derivation/guide.md +130 -0
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-CN/skills/methodology-system/SKILL.md +78 -0
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/methodology-system → methodology-system}/runtime.md +3 -3
- package/bundled/locales/zh-CN/skills/project-discovery/SKILL.md +66 -0
- package/bundled/locales/zh-CN/skills/project-discovery/guide.md +371 -0
- package/bundled/locales/zh-CN/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +4 -4
- package/bundled/locales/zh-CN/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +1 -1
- package/bundled/locales/zh-CN/skills/refactoring-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -8
- package/bundled/locales/zh-CN/skills/release-standards/SKILL.md +64 -0
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/changelog-format.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +5 -6
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/release-workflow.md +7 -7
- package/bundled/locales/zh-CN/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +3 -3
- package/bundled/locales/zh-CN/skills/requirement-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +4 -5
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +3 -3
- package/bundled/locales/zh-CN/skills/reverse-engineer/SKILL.md +67 -0
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +17 -18
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +2 -2
- package/bundled/locales/zh-CN/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +3 -3
- package/bundled/locales/zh-CN/skills/spec-driven-dev/SKILL.md +75 -0
- package/bundled/locales/zh-CN/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +10 -11
- package/bundled/locales/zh-CN/skills/tdd-assistant/SKILL.md +66 -0
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +12 -16
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/locales/zh-CN/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +3 -3
- package/bundled/locales/zh-CN/skills/test-coverage-assistant/SKILL.md +65 -0
- package/bundled/locales/zh-CN/skills/test-coverage-assistant/guide.md +284 -0
- package/bundled/locales/zh-CN/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +8 -8
- package/bundled/locales/zh-CN/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +4 -4
- package/bundled/locales/zh-CN/skills/{cline → tools/cline}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{copilot → tools/copilot}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{copilot → tools/copilot}/copilot-instructions.md +1 -1
- package/bundled/locales/zh-CN/skills/{cursor → tools/cursor}/README.md +1 -1
- package/bundled/locales/zh-CN/skills/{windsurf → tools/windsurf}/README.md +1 -1
- package/bundled/locales/zh-TW/CHANGELOG.md +16 -16
- package/bundled/locales/zh-TW/CLAUDE.md +3 -3
- package/bundled/locales/zh-TW/MAINTENANCE.md +7 -7
- package/bundled/locales/zh-TW/README.md +13 -7
- package/bundled/locales/zh-TW/STANDARDS-MAPPING.md +1 -1
- package/bundled/locales/zh-TW/adoption/ADOPTION-GUIDE.md +4 -4
- package/bundled/locales/zh-TW/adoption/DAILY-WORKFLOW-GUIDE.md +66 -7
- package/bundled/locales/zh-TW/adoption/STATIC-DYNAMIC-GUIDE.md +22 -22
- package/bundled/locales/zh-TW/adoption/checklists/enterprise.md +5 -5
- package/bundled/locales/zh-TW/adoption/checklists/minimal.md +4 -4
- package/bundled/locales/zh-TW/adoption/checklists/recommended.md +5 -5
- package/bundled/locales/zh-TW/ai/MAINTENANCE.md +13 -13
- package/bundled/locales/zh-TW/ai/standards/anti-hallucination.ai.yaml +3 -2
- package/bundled/locales/zh-TW/ai/standards/git-workflow.ai.yaml +4 -3
- package/bundled/locales/zh-TW/ai/standards/spec-driven-development.ai.yaml +3 -3
- package/bundled/locales/zh-TW/ai/standards/testing.ai.yaml +1 -0
- package/bundled/locales/zh-TW/core/ai-instruction-standards.md +1 -1
- package/bundled/locales/zh-TW/core/anti-hallucination.md +38 -701
- package/bundled/locales/zh-TW/core/changelog-standards.md +1 -1
- package/bundled/locales/zh-TW/core/checkin-standards.md +18 -5
- package/bundled/locales/zh-TW/core/code-review-checklist.md +1 -1
- package/bundled/locales/zh-TW/core/commit-message-guide.md +1 -1
- package/bundled/locales/zh-TW/core/developer-memory.md +576 -0
- package/bundled/locales/zh-TW/core/documentation-structure.md +115 -22
- package/bundled/locales/zh-TW/core/documentation-writing-standards.md +126 -5
- package/bundled/locales/zh-TW/core/forward-derivation-standards.md +2 -2
- package/bundled/locales/zh-TW/core/git-workflow.md +38 -812
- package/bundled/locales/zh-TW/core/guides/anti-hallucination-guide.md +779 -0
- package/bundled/locales/zh-TW/core/guides/git-workflow-guide.md +1016 -0
- package/bundled/locales/zh-TW/core/guides/refactoring-guide.md +864 -0
- package/bundled/locales/zh-TW/core/guides/testing-guide.md +2280 -0
- package/bundled/locales/zh-TW/core/logging-standards.md +159 -4
- package/bundled/locales/zh-TW/core/project-structure.md +102 -9
- package/bundled/locales/zh-TW/core/refactoring-standards.md +37 -823
- package/bundled/locales/zh-TW/core/reverse-engineering-standards.md +6 -6
- package/bundled/locales/zh-TW/core/spec-driven-development.md +17 -268
- package/bundled/locales/zh-TW/core/test-completeness-dimensions.md +128 -14
- package/bundled/locales/zh-TW/core/test-driven-development.md +20 -983
- package/bundled/locales/zh-TW/core/testing-standards.md +120 -2105
- package/bundled/locales/zh-TW/core/versioning.md +13 -55
- package/bundled/locales/zh-TW/docs/AI-AGENT-ROADMAP.md +90 -51
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +184 -0
- package/bundled/locales/zh-TW/docs/CLI-FLOW.md +239 -0
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +320 -0
- package/bundled/locales/zh-TW/docs/MIGRATION-V5.md +71 -0
- package/bundled/locales/zh-TW/docs/OPERATION-WORKFLOW.md +42 -42
- package/bundled/locales/zh-TW/docs/STANDARDS-REFERENCE.md +440 -0
- package/bundled/locales/zh-TW/docs/USAGE-MODES-COMPARISON.md +1 -1
- package/bundled/locales/zh-TW/docs/WINDOWS-GUIDE.md +1 -1
- package/bundled/locales/zh-TW/integrations/claude-code/README.md +44 -0
- package/bundled/locales/zh-TW/integrations/github-copilot/copilot-instructions.md +3 -3
- package/bundled/locales/zh-TW/integrations/github-copilot/skills-mapping.md +18 -6
- package/bundled/locales/zh-TW/integrations/opencode/skills-mapping.md +22 -10
- package/bundled/locales/zh-TW/methodologies/guides/sdd-guide.md +338 -0
- package/bundled/locales/zh-TW/methodologies/guides/tdd-guide.md +1055 -0
- package/bundled/locales/zh-TW/options/commit-message/bilingual.md +1 -1
- package/bundled/locales/zh-TW/options/commit-message/english.md +1 -1
- package/bundled/locales/zh-TW/options/commit-message/traditional-chinese.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/gitflow.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/github-flow.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/merge-commit.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/rebase-ff.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/squash-merge.md +1 -1
- package/bundled/locales/zh-TW/options/git-workflow/trunk-based.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/dotnet.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/go.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/java.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/nodejs.md +1 -1
- package/bundled/locales/zh-TW/options/project-structure/python.md +1 -1
- package/bundled/locales/zh-TW/options/testing/e2e-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/integration-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/system-testing.md +1 -1
- package/bundled/locales/zh-TW/options/testing/unit-testing.md +1 -1
- package/bundled/locales/zh-TW/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +2 -2
- package/bundled/locales/zh-TW/skills/README.md +131 -79
- package/bundled/locales/zh-TW/skills/agents/README.md +281 -0
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +7 -7
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +8 -8
- package/bundled/locales/zh-TW/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +8 -8
- package/bundled/locales/zh-TW/skills/ai-friendly-architecture/SKILL.md +221 -0
- package/bundled/locales/zh-TW/skills/ai-instruction-standards/SKILL.md +214 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/SKILL.md +71 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/acceptance-criteria-guide.md +428 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/atdd-workflow.md +484 -0
- package/bundled/locales/zh-TW/skills/atdd-assistant/guide.md +368 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/SKILL.md +68 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/bdd-workflow.md +406 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/gherkin-guide.md +454 -0
- package/bundled/locales/zh-TW/skills/bdd-assistant/guide.md +324 -0
- package/bundled/locales/zh-TW/skills/changelog-guide/SKILL.md +64 -0
- package/bundled/locales/zh-TW/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +6 -7
- package/bundled/locales/zh-TW/skills/checkin-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-TW/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -7
- package/bundled/locales/zh-TW/skills/code-review-assistant/SKILL.md +56 -0
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/methodology.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/commands → commands}/refactor.md +3 -3
- package/bundled/locales/zh-TW/skills/commit-standards/SKILL.md +61 -0
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +5 -6
- package/bundled/locales/zh-TW/skills/{claude-code/commit-standards → commit-standards}/language-options.md +3 -3
- package/bundled/locales/zh-TW/skills/docs-generator/SKILL.md +59 -0
- package/bundled/locales/zh-TW/skills/docs-generator/guide.md +262 -0
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -8
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/forward-derivation/SKILL.md +62 -0
- package/bundled/locales/zh-TW/skills/{claude-code/forward-derivation/SKILL.md → forward-derivation/guide.md} +24 -19
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/methodology-system/SKILL.md +78 -0
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/methodology-system → methodology-system}/runtime.md +3 -3
- package/bundled/locales/zh-TW/skills/project-discovery/SKILL.md +66 -0
- package/bundled/locales/zh-TW/skills/project-discovery/guide.md +371 -0
- package/bundled/locales/zh-TW/skills/project-discovery/workflow.md +574 -0
- package/bundled/locales/zh-TW/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +4 -4
- package/bundled/locales/zh-TW/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +1 -1
- package/bundled/locales/zh-TW/skills/refactoring-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -8
- package/bundled/locales/zh-TW/skills/release-standards/SKILL.md +64 -0
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/changelog-format.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/release-workflow.md +60 -28
- package/bundled/locales/zh-TW/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +3 -3
- package/bundled/locales/zh-TW/skills/requirement-assistant/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +2 -3
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +3 -3
- package/bundled/locales/zh-TW/skills/reverse-engineer/SKILL.md +67 -0
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +17 -18
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +2 -2
- package/bundled/locales/zh-TW/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +3 -3
- package/bundled/locales/zh-TW/skills/spec-driven-dev/SKILL.md +75 -0
- package/bundled/locales/zh-TW/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +9 -10
- package/bundled/locales/zh-TW/skills/tdd-assistant/SKILL.md +66 -0
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +9 -10
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/locales/zh-TW/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +3 -3
- package/bundled/locales/zh-TW/skills/test-coverage-assistant/SKILL.md +65 -0
- package/bundled/locales/zh-TW/skills/{claude-code/test-coverage-assistant/SKILL.md → test-coverage-assistant/guide.md} +27 -24
- package/bundled/locales/zh-TW/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +6 -6
- package/bundled/locales/zh-TW/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +4 -4
- package/bundled/locales/zh-TW/skills/{cline → tools/cline}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{copilot → tools/copilot}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{copilot → tools/copilot}/copilot-instructions.md +1 -1
- package/bundled/locales/zh-TW/skills/{cursor → tools/cursor}/README.md +1 -1
- package/bundled/locales/zh-TW/skills/{windsurf → tools/windsurf}/README.md +1 -1
- package/bundled/skills/INTEGRATION-GUIDE.md +210 -0
- package/bundled/skills/README.md +95 -0
- package/bundled/skills/_shared/README.md +60 -0
- package/bundled/skills/{claude-code/agents → agents}/README.md +2 -2
- package/bundled/skills/{claude-code/agents → agents}/code-architect.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/doc-writer.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/reviewer.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/spec-analyst.md +1 -1
- package/bundled/skills/{claude-code/agents → agents}/test-specialist.md +1 -1
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/SKILL.md +28 -5
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/anti-hallucination.md +24 -5
- package/bundled/skills/{claude-code/ai-collaboration-standards → ai-collaboration-standards}/certainty-labels.md +31 -6
- package/bundled/skills/ai-friendly-architecture/SKILL.md +216 -0
- package/bundled/skills/ai-instruction-standards/SKILL.md +209 -0
- package/bundled/skills/atdd-assistant/SKILL.md +74 -0
- package/bundled/skills/{claude-code/atdd-assistant → atdd-assistant}/acceptance-criteria-guide.md +1 -1
- package/bundled/skills/{claude-code/atdd-assistant → atdd-assistant}/atdd-workflow.md +1 -1
- package/bundled/skills/{claude-code/atdd-assistant/SKILL.md → atdd-assistant/guide.md} +11 -11
- package/bundled/skills/bdd-assistant/SKILL.md +70 -0
- package/bundled/skills/{claude-code/bdd-assistant → bdd-assistant}/bdd-workflow.md +1 -1
- package/bundled/skills/{claude-code/bdd-assistant → bdd-assistant}/gherkin-guide.md +1 -1
- package/bundled/skills/{claude-code/bdd-assistant/SKILL.md → bdd-assistant/guide.md} +11 -11
- package/bundled/skills/changelog-guide/SKILL.md +66 -0
- package/bundled/skills/{claude-code/changelog-guide/SKILL.md → changelog-guide/guide.md} +8 -6
- package/bundled/skills/checkin-assistant/SKILL.md +52 -0
- package/bundled/skills/{claude-code/checkin-assistant/SKILL.md → checkin-assistant/guide.md} +6 -6
- package/bundled/skills/code-review-assistant/SKILL.md +53 -0
- package/bundled/skills/{claude-code/code-review-assistant → code-review-assistant}/checkin-checklist.md +3 -3
- package/bundled/skills/{claude-code/code-review-assistant/SKILL.md → code-review-assistant/guide.md} +7 -5
- package/bundled/skills/{claude-code/code-review-assistant → code-review-assistant}/review-checklist.md +3 -3
- package/bundled/skills/commands/COMMAND-FAMILY-OVERVIEW.md +290 -0
- package/bundled/skills/{claude-code/commands → commands}/README.md +13 -3
- package/bundled/skills/{claude-code/commands → commands}/atdd.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/bdd.md +2 -2
- package/bundled/skills/commands/changelog.md +58 -0
- package/bundled/skills/{claude-code/commands → commands}/check.md +1 -1
- package/bundled/skills/commands/checkin.md +53 -0
- package/bundled/skills/{claude-code/commands → commands}/commit.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/config.md +1 -1
- package/bundled/skills/{claude-code/commands → commands}/coverage.md +5 -4
- package/bundled/skills/commands/derive-all.md +53 -0
- package/bundled/skills/commands/derive-atdd.md +49 -0
- package/bundled/skills/commands/derive-bdd.md +47 -0
- package/bundled/skills/commands/derive-tdd.md +48 -0
- package/bundled/skills/commands/derive.md +72 -0
- package/bundled/skills/commands/discover.md +80 -0
- package/bundled/skills/commands/docgen.md +61 -0
- package/bundled/skills/commands/docs.md +59 -0
- package/bundled/skills/commands/guide.md +44 -0
- package/bundled/skills/{claude-code/commands → commands}/init.md +2 -2
- package/bundled/skills/{claude-code/commands → commands}/methodology.md +32 -16
- package/bundled/skills/{claude-code/commands → commands}/refactor.md +2 -2
- package/bundled/skills/commands/release.md +56 -0
- package/bundled/skills/{claude-code/commands → commands}/requirement.md +3 -3
- package/bundled/skills/commands/reverse-bdd.md +47 -0
- package/bundled/skills/commands/reverse-sdd.md +51 -0
- package/bundled/skills/commands/reverse-tdd.md +51 -0
- package/bundled/skills/commands/reverse.md +63 -0
- package/bundled/skills/{claude-code/commands → commands}/review.md +3 -3
- package/bundled/skills/commands/sdd.md +135 -0
- package/bundled/skills/{claude-code/commands → commands}/tdd.md +3 -3
- package/bundled/skills/{claude-code/commands → commands}/update.md +2 -2
- package/bundled/skills/commit-standards/SKILL.md +60 -0
- package/bundled/skills/{claude-code/commit-standards → commit-standards}/conventional-commits.md +3 -3
- package/bundled/skills/{claude-code/commit-standards/SKILL.md → commit-standards/guide.md} +17 -5
- package/bundled/skills/{claude-code/commit-standards → commit-standards}/language-options.md +2 -2
- package/bundled/skills/docs-generator/SKILL.md +69 -0
- package/bundled/skills/docs-generator/guide.md +258 -0
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/SKILL.md +7 -7
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/documentation-structure.md +3 -3
- package/bundled/skills/{claude-code/documentation-guide → documentation-guide}/readme-template.md +2 -2
- package/bundled/skills/{claude-code/error-code-guide → error-code-guide}/SKILL.md +7 -5
- package/bundled/skills/forward-derivation/SKILL.md +61 -0
- package/bundled/skills/{claude-code/forward-derivation/SKILL.md → forward-derivation/guide.md} +44 -29
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/SKILL.md +7 -5
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/branch-naming.md +2 -2
- package/bundled/skills/{claude-code/git-workflow-guide → git-workflow-guide}/git-workflow.md +3 -3
- package/bundled/skills/{claude-code/logging-guide → logging-guide}/SKILL.md +7 -5
- package/bundled/skills/methodology-system/SKILL.md +75 -0
- package/bundled/skills/{claude-code/methodology-system → methodology-system}/create-methodology.md +1 -1
- package/bundled/skills/{claude-code/methodology-system/SKILL.md → methodology-system/guide.md} +51 -16
- package/bundled/skills/methodology-system/integrated-flow.md +454 -0
- package/bundled/skills/{claude-code/methodology-system → methodology-system}/runtime.md +2 -2
- package/bundled/skills/project-discovery/SKILL.md +63 -0
- package/bundled/skills/project-discovery/guide.md +367 -0
- package/bundled/skills/project-discovery/workflow.md +566 -0
- package/bundled/skills/{claude-code/project-structure-guide → project-structure-guide}/SKILL.md +14 -4
- package/bundled/skills/refactoring-assistant/SKILL.md +78 -0
- package/bundled/skills/{claude-code/refactoring-assistant/SKILL.md → refactoring-assistant/guide.md} +7 -7
- package/bundled/skills/release-standards/SKILL.md +61 -0
- package/bundled/skills/{claude-code/release-standards → release-standards}/changelog-format.md +2 -2
- package/bundled/skills/{claude-code/release-standards/SKILL.md → release-standards/guide.md} +7 -5
- package/bundled/skills/{claude-code/release-standards → release-standards}/release-workflow.md +59 -24
- package/bundled/skills/{claude-code/release-standards → release-standards}/semantic-versioning.md +2 -2
- package/bundled/skills/requirement-assistant/SKILL.md +66 -0
- package/bundled/skills/{claude-code/requirement-assistant/SKILL.md → requirement-assistant/guide.md} +14 -6
- package/bundled/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-checklist.md +2 -2
- package/bundled/skills/{claude-code/requirement-assistant → requirement-assistant}/requirement-writing.md +2 -2
- package/bundled/skills/reverse-engineer/SKILL.md +64 -0
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/bdd-extraction.md +1 -1
- package/bundled/skills/{claude-code/reverse-engineer/SKILL.md → reverse-engineer/guide.md} +21 -18
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/tdd-analysis.md +1 -1
- package/bundled/skills/{claude-code/reverse-engineer → reverse-engineer}/workflow.md +2 -2
- package/bundled/skills/spec-driven-dev/SKILL.md +80 -0
- package/bundled/skills/{claude-code/spec-driven-dev/SKILL.md → spec-driven-dev/guide.md} +50 -8
- package/bundled/skills/tdd-assistant/SKILL.md +65 -0
- package/bundled/skills/{claude-code/tdd-assistant/SKILL.md → tdd-assistant/guide.md} +10 -10
- package/bundled/skills/{claude-code/tdd-assistant → tdd-assistant}/language-examples.md +3 -3
- package/bundled/skills/{claude-code/tdd-assistant → tdd-assistant}/tdd-workflow.md +2 -2
- package/bundled/skills/test-coverage-assistant/SKILL.md +63 -0
- package/bundled/skills/{claude-code/test-coverage-assistant/SKILL.md → test-coverage-assistant/guide.md} +39 -24
- package/bundled/skills/{claude-code/testing-guide → testing-guide}/SKILL.md +12 -7
- package/bundled/skills/{claude-code/testing-guide → testing-guide}/testing-pyramid.md +3 -3
- package/bundled/skills/testing-guide/testing-theory.md +2291 -0
- package/bundled/skills/tools/cline/.clinerules +79 -0
- package/bundled/skills/tools/cline/README.md +50 -0
- package/bundled/skills/tools/copilot/README.md +99 -0
- package/bundled/skills/tools/copilot/copilot-instructions.md +71 -0
- package/bundled/skills/tools/cursor/.cursorrules +101 -0
- package/bundled/skills/tools/cursor/README.md +50 -0
- package/bundled/skills/tools/windsurf/.windsurfrules +76 -0
- package/bundled/skills/tools/windsurf/README.md +51 -0
- package/bundled/skills/{claude-code/workflows → workflows}/README.md +1 -1
- package/bundled/skills/workflows/release.workflow.yaml +893 -0
- package/package.json +4 -1
- package/src/commands/check.js +195 -130
- package/src/commands/config.js +1262 -0
- package/src/commands/configure.js +3 -950
- package/src/commands/fix.js +53 -0
- package/src/commands/hitl.js +19 -0
- package/src/commands/init.js +320 -1030
- package/src/commands/list.js +1 -1
- package/src/commands/simulate.js +61 -0
- package/src/commands/spec.js +288 -0
- package/src/commands/start.js +373 -0
- package/src/commands/sweep.js +142 -0
- package/src/commands/update.js +136 -19
- package/src/commands/workflow.js +265 -1
- package/src/config/ai-agent-paths.js +89 -29
- package/src/core/constants.js +7 -1
- package/src/core/manifest.js +1 -0
- package/src/flows/init-flow.js +243 -0
- package/src/hitl/checkpoint.js +80 -0
- package/src/hitl/classifier.js +54 -0
- package/src/hitl/manager.js +88 -0
- package/src/i18n/messages.js +907 -99
- package/src/index.js +1 -0
- package/src/installers/integration-installer.js +237 -0
- package/src/installers/manifest-installer.js +131 -0
- package/src/installers/skills-installer.js +286 -0
- package/src/installers/standards-installer.js +193 -0
- package/src/missions/MissionManager.js +501 -0
- package/src/prompts/init.js +228 -130
- package/src/prompts/integrations.js +13 -1
- package/src/schemas/standard.schema.json +117 -0
- package/src/utils/agents-installer.js +2 -2
- package/src/utils/config-loader.js +47 -0
- package/src/utils/config-manager.js +108 -0
- package/src/utils/config-merger.js +47 -0
- package/src/utils/github.js +22 -18
- package/src/utils/inquirer-patch.js +98 -0
- package/src/utils/integration-generator.js +392 -58
- package/src/utils/reference-sync.js +69 -19
- package/src/utils/skills-installer.js +6 -3
- package/src/utils/standard-fixer.js +141 -0
- package/src/utils/standard-validator.js +329 -0
- package/src/utils/workflow-executor.js +886 -0
- package/src/utils/workflow-state.js +404 -0
- package/src/utils/workflows-installer.js +2 -2
- package/src/vibe/auto-sweep.js +349 -0
- package/src/vibe/micro-spec.js +428 -0
- package/standards-registry.json +278 -102
- package/bundled/locales/zh-CN/skills/claude-code/README.md +0 -174
- package/bundled/locales/zh-CN/skills/claude-code/test-coverage-assistant/SKILL.md +0 -282
- package/bundled/locales/zh-TW/skills/claude-code/README.md +0 -174
- package/bundled/skills/claude-code/README.md +0 -215
- package/bundled/skills/claude-code/commands/changelog.md +0 -57
- package/bundled/skills/claude-code/commands/derive-all.md +0 -214
- package/bundled/skills/claude-code/commands/derive-atdd.md +0 -177
- package/bundled/skills/claude-code/commands/derive-bdd.md +0 -158
- package/bundled/skills/claude-code/commands/derive-tdd.md +0 -259
- package/bundled/skills/claude-code/commands/docs.md +0 -75
- package/bundled/skills/claude-code/commands/release.md +0 -50
- package/bundled/skills/claude-code/commands/reverse-bdd.md +0 -264
- package/bundled/skills/claude-code/commands/reverse-spec.md +0 -185
- package/bundled/skills/claude-code/commands/reverse-tdd.md +0 -351
- package/bundled/skills/claude-code/commands/spec.md +0 -69
- package/bundled/skills/claude-code/methodology-system/integrated-flow.md +0 -322
- /package/bundled/skills/{claude-code/CONTRIBUTING.template.md → CONTRIBUTING.template.md} +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/checkin.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/commit.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/refactoring.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/ai → ai}/standards/testing.ai.yaml +0 -0
- /package/bundled/skills/{claude-code/project-structure-guide → project-structure-guide}/language-patterns.md +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/code-review.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/feature-dev.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/integrated-flow.workflow.yaml +0 -0
- /package/bundled/skills/{claude-code/workflows → workflows}/large-codebase-analysis.workflow.yaml +0 -0
|
@@ -1,1004 +1,41 @@
|
|
|
1
|
-
---
|
|
2
|
-
source: ../../../core/test-driven-development.md
|
|
3
|
-
source_version: 1.1.0
|
|
4
|
-
translation_version: 1.1.0
|
|
5
|
-
last_synced: 2026-01-12
|
|
6
|
-
status: current
|
|
7
|
-
---
|
|
8
|
-
|
|
9
1
|
# 測試驅動開發 (TDD) 標準
|
|
10
2
|
|
|
11
|
-
**版本**: 1.1.0
|
|
12
|
-
**最後更新**: 2026-01-12
|
|
13
|
-
**適用範圍**: 所有採用測試驅動開發的專案
|
|
14
|
-
|
|
15
3
|
> **語言**: [English](../../../core/test-driven-development.md) | 繁體中文
|
|
16
4
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
本標準定義了測試驅動開發 (TDD) 的原則、工作流程和最佳實踐,確保測試能夠驅動軟體功能的設計與實作。
|
|
22
|
-
|
|
23
|
-
**主要優點**:
|
|
24
|
-
- 設計從測試中浮現,產生更具可測試性和模組化的程式碼
|
|
25
|
-
- 對程式碼正確性獲得即時回饋
|
|
26
|
-
- 測試作為活文件
|
|
27
|
-
- 減少除錯時間和缺陷率
|
|
28
|
-
- 對重構更有信心
|
|
5
|
+
**版本**: 1.2.0
|
|
6
|
+
**最後更新**: 2026-01-25
|
|
7
|
+
**適用性**: 所有採用測試驅動開發的專案
|
|
8
|
+
**範圍**: 通用 (Universal)
|
|
29
9
|
|
|
30
10
|
---
|
|
31
11
|
|
|
32
|
-
##
|
|
33
|
-
|
|
34
|
-
1. [TDD 核心循環](#tdd-核心循環)
|
|
35
|
-
2. [TDD 原則](#tdd-原則)
|
|
36
|
-
3. [適用場景指南](#適用場景指南)
|
|
37
|
-
4. [TDD vs BDD vs ATDD](#tdd-vs-bdd-vs-atdd)
|
|
38
|
-
5. [與 SDD 整合](#與-sdd-整合)
|
|
39
|
-
6. [TDD 工作流程](#tdd-工作流程)
|
|
40
|
-
7. [測試設計指南](#測試設計指南)
|
|
41
|
-
8. [重構策略](#重構策略)
|
|
42
|
-
9. [TDD 中的測試替身](#tdd-中的測試替身)
|
|
43
|
-
10. [反模式與修復](#反模式與修復)
|
|
44
|
-
11. [語言/框架實踐](#語言框架實踐)
|
|
45
|
-
12. [度量與評估](#度量與評估)
|
|
46
|
-
13. [相關標準](#相關標準)
|
|
47
|
-
14. [參考資料](#參考資料)
|
|
48
|
-
15. [版本歷史](#版本歷史)
|
|
49
|
-
16. [授權](#授權)
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## TDD 核心循環
|
|
54
|
-
|
|
55
|
-
### 紅-綠-重構循環
|
|
56
|
-
|
|
57
|
-
TDD 遵循一個簡單但強大的迭代循環:
|
|
12
|
+
## 摘要
|
|
58
13
|
|
|
59
|
-
|
|
60
|
-
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
61
|
-
│ TDD 核心循環 │
|
|
62
|
-
├─────────────────────────────────────────────────────────────────────────────┤
|
|
63
|
-
│ │
|
|
64
|
-
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
|
|
65
|
-
│ │ 🔴 紅 │────────▶│ 🟢 綠 │────────▶│🔵 重構 │ │
|
|
66
|
-
│ └─────────┘ └─────────┘ └─────────┘ │
|
|
67
|
-
│ ▲ │ │
|
|
68
|
-
│ │ │ │
|
|
69
|
-
│ └────────────────────────────────────────┘ │
|
|
70
|
-
│ │
|
|
71
|
-
│ 🔴 紅色階段 (1-5 分鐘) │
|
|
72
|
-
│ ├─ 撰寫一個描述預期行為的失敗測試 │
|
|
73
|
-
│ ├─ 測試應該因為「正確的原因」而失敗 │
|
|
74
|
-
│ └─ 驗證測試確實失敗 │
|
|
75
|
-
│ │
|
|
76
|
-
│ 🟢 綠色階段 (1-10 分鐘) │
|
|
77
|
-
│ ├─ 撰寫「最少」的程式碼讓測試通過 │
|
|
78
|
-
│ ├─ 「先假裝,再實現」是可以接受的 │
|
|
79
|
-
│ └─ 不要過度設計;只要讓它能運作 │
|
|
80
|
-
│ │
|
|
81
|
-
│ 🔵 重構階段 (5-15 分鐘) │
|
|
82
|
-
│ ├─ 在保持測試綠色的同時改善程式碼品質 │
|
|
83
|
-
│ ├─ 消除重複 (DRY) │
|
|
84
|
-
│ ├─ 改善命名、結構、可讀性 │
|
|
85
|
-
│ └─ 每次重構步驟後執行測試 │
|
|
86
|
-
│ │
|
|
87
|
-
└─────────────────────────────────────────────────────────────────────────────┘
|
|
88
|
-
```
|
|
14
|
+
測試驅動開發 (TDD) 是一種傳統開發方法論 (1999),以測試驅動軟體功能的設計與實作。核心工作流程遵循 **紅-綠-重構 (Red-Green-Refactor)** 循環:
|
|
89
15
|
|
|
90
|
-
|
|
16
|
+
1. **紅 (Red)**:撰寫一個描述預期行為的失敗測試
|
|
17
|
+
2. **綠 (Green)**:撰寫最少量的程式碼讓測試通過
|
|
18
|
+
3. **重構 (Refactor)**:在保持測試通過的同時改善程式碼品質
|
|
91
19
|
|
|
92
|
-
|
|
93
|
-
|------|---------|---------|
|
|
94
|
-
| 🔴 紅 | 1-5 分鐘 | 若超過 10 分鐘,測試範圍太大 |
|
|
95
|
-
| 🟢 綠 | 1-10 分鐘 | 若超過 15 分鐘,需要分解問題 |
|
|
96
|
-
| 🔵 重構 | 5-15 分鐘 | 若跳過,技術債會累積 |
|
|
97
|
-
|
|
98
|
-
### 口訣
|
|
99
|
-
|
|
100
|
-
> **紅 → 綠 → 重構 → 重複**
|
|
101
|
-
|
|
102
|
-
每次迭代都應該很小。如果你發現自己在任何階段花費太長時間,測試可能太有野心了。
|
|
20
|
+
TDD 是傳統測試驅動開發家族的一部分(與 BDD 和 ATDD 並列),可用於 AI 時代 SDD(規格驅動開發)工作流程的實作階段。此方法論促進可測試、模組化的程式碼設計,並提供關於程式碼正確性的即時回饋。
|
|
103
21
|
|
|
104
22
|
---
|
|
105
23
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
### FIRST 原則
|
|
109
|
-
|
|
110
|
-
高品質的測試遵循 FIRST 原則:
|
|
111
|
-
|
|
112
|
-
| 原則 | 說明 | 實踐指南 |
|
|
113
|
-
|------|------|---------|
|
|
114
|
-
| **F**ast (快速) | 測試應該快速執行 | 單元測試每個 < 100ms;總測試套件 < 10s |
|
|
115
|
-
| **I**ndependent (獨立) | 測試之間不互相依賴 | 無共享狀態;每個測試設置自己的資料 |
|
|
116
|
-
| **R**epeatable (可重複) | 每次執行結果相同 | 無隨機性;無時間依賴;無外部 I/O |
|
|
117
|
-
| **S**elf-validating (自我驗證) | 有明確的通過/失敗結果 | 不需手動檢查;明確的斷言 |
|
|
118
|
-
| **T**imely (及時) | 在生產程式碼之前撰寫 | 這是 TDD 的本質 |
|
|
119
|
-
|
|
120
|
-
### Uncle Bob 的 TDD 三規則
|
|
121
|
-
|
|
122
|
-
Robert C. Martin (Uncle Bob) 用三條嚴格的規則定義 TDD:
|
|
123
|
-
|
|
124
|
-
1. **規則一(紅色規則)**:除非是為了讓失敗的單元測試通過,否則不允許撰寫任何生產程式碼。
|
|
125
|
-
|
|
126
|
-
2. **規則二(測試規則)**:不允許撰寫超過足以失敗的單元測試;編譯失敗也算失敗。
|
|
127
|
-
|
|
128
|
-
3. **規則三(綠色規則)**:不允許撰寫超過足以讓當前失敗測試通過的生產程式碼。
|
|
129
|
-
|
|
130
|
-
### 測試的單一職責
|
|
131
|
-
|
|
132
|
-
每個測試應該驗證「一個」行為:
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
✅ 好:test_calculate_total_with_discount_applies_percentage()
|
|
136
|
-
❌ 差:test_calculate_total_and_tax_and_discount_and_shipping()
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### 測試即文件
|
|
140
|
-
|
|
141
|
-
良好撰寫的測試可作為可執行的文件:
|
|
142
|
-
|
|
143
|
-
```
|
|
144
|
-
✅ 好的測試名稱:
|
|
145
|
-
- should_return_empty_list_when_no_users_found
|
|
146
|
-
- should_throw_validation_error_when_email_is_invalid
|
|
147
|
-
- should_calculate_discount_when_order_exceeds_threshold
|
|
148
|
-
|
|
149
|
-
❌ 差的測試名稱:
|
|
150
|
-
- test1
|
|
151
|
-
- testCalculate
|
|
152
|
-
- itWorks
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
-
## 適用場景指南
|
|
158
|
-
|
|
159
|
-
### TDD 場景適用性
|
|
160
|
-
|
|
161
|
-
| 場景 | 評分 | 說明 |
|
|
162
|
-
|------|------|------|
|
|
163
|
-
| **新功能開發** | ⭐⭐⭐⭐⭐ | TDD 最佳使用場景;設計從測試中浮現 |
|
|
164
|
-
| **Bug 修復** | ⭐⭐⭐⭐⭐ | 先撰寫失敗測試重現 bug |
|
|
165
|
-
| **API 設計** | ⭐⭐⭐⭐⭐ | 測試即 API 使用文件 |
|
|
166
|
-
| **核心業務邏輯** | ⭐⭐⭐⭐⭐ | 高價值程式碼必須有測試保護 |
|
|
167
|
-
| **演算法實現** | ⭐⭐⭐⭐ | 邊界情況多;TDD 幫助思考 |
|
|
168
|
-
| **重構現有程式碼** | ⭐⭐⭐⭐ | 先補測試,再安全重構 |
|
|
169
|
-
| **UI 組件** | ⭐⭐⭐ | 部分適用;可結合 BDD |
|
|
170
|
-
| **探索性原型** | ⭐⭐ | TDD 可能拖慢不確定的探索 |
|
|
171
|
-
| **一次性腳本** | ⭐ | 成本效益比低 |
|
|
172
|
-
| **第三方整合** | ⭐⭐ | 難以 Mock;改用整合測試 |
|
|
173
|
-
|
|
174
|
-
### 依專案類型的 TDD
|
|
175
|
-
|
|
176
|
-
| 專案類型 | TDD | BDD | ATDD | 建議 |
|
|
177
|
-
|---------|-----|-----|------|------|
|
|
178
|
-
| **新創 MVP** | ⚠️ 選擇性 | ✅ 推薦 | ❌ | 快速迭代優先 |
|
|
179
|
-
| **企業應用** | ✅ 推薦 | ✅ 推薦 | ✅ 推薦 | 品質與可維護性關鍵 |
|
|
180
|
-
| **開源專案** | ✅ 推薦 | ⚠️ 選擇性 | ❌ | 貢獻者需要測試文件 |
|
|
181
|
-
| **遺留系統改造** | ✅ 必要 | ⚠️ 選擇性 | ❌ | 使用 Golden Master 策略(見下方) |
|
|
182
|
-
| **微服務** | ✅ 推薦 | ✅ 推薦 | ✅ 推薦 | 契約測試重要 |
|
|
183
|
-
| **資料管線** | ⚠️ 選擇性 | ❌ | ❌ | 以整合測試為主 |
|
|
184
|
-
| **機器學習** | 🔶 視情況 | ❌ | ❌ | 見下方 ML 測試邊界 |
|
|
185
|
-
|
|
186
|
-
### 機器學習 (ML) 測試邊界
|
|
187
|
-
|
|
188
|
-
**重要**:ML 專案需要區分「模型效果」和「資料工程」:
|
|
189
|
-
|
|
190
|
-
| 面向 | TDD 適用性 | 說明 |
|
|
191
|
-
|------|-----------|------|
|
|
192
|
-
| **模型準確率** | ❌ 不適用 | 結果不確定性高;難以預先定義期望值 |
|
|
193
|
-
| **特徵處理** | ✅ 必須 | 避免 Garbage In, Garbage Out |
|
|
194
|
-
| **資料清洗** | ✅ 必須 | 資料品質直接影響模型效果 |
|
|
195
|
-
| **資料轉換** | ✅ 必須 | 確保轉換邏輯正確 |
|
|
196
|
-
| **管線整合** | ⚠️ 選擇性 | 以整合測試為主 |
|
|
197
|
-
|
|
198
|
-
### 遺留系統策略:Golden Master Testing(黃金大師測試)
|
|
199
|
-
|
|
200
|
-
**問題**:在沒有測試的遺留系統中,「補測試」本身就有破壞現有邏輯的風險。
|
|
201
|
-
|
|
202
|
-
**Golden Master Testing 工作流程**:
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
206
|
-
│ Golden Master Testing 工作流程 │
|
|
207
|
-
├─────────────────────────────────────────────────────────────────┤
|
|
208
|
-
│ │
|
|
209
|
-
│ 1️⃣ 錄製階段(不修改程式碼) │
|
|
210
|
-
│ ├─ 對系統執行大量輸入 │
|
|
211
|
-
│ ├─ 記錄所有輸出作為「黃金基準」 │
|
|
212
|
-
│ └─ 使用自動化工具或 AI 生成測試案例 │
|
|
213
|
-
│ │
|
|
214
|
-
│ 2️⃣ 驗證階段 │
|
|
215
|
-
│ ├─ 建立 Snapshot/Approval 測試 │
|
|
216
|
-
│ └─ 確保重構前後輸出一致 │
|
|
217
|
-
│ │
|
|
218
|
-
│ 3️⃣ 重構階段 │
|
|
219
|
-
│ ├─ 在 Golden Master 保護下安全重構 │
|
|
220
|
-
│ ├─ 每次修改後執行 Golden Master 測試 │
|
|
221
|
-
│ └─ 逐步將 Golden Master 轉換為正式的單元測試 │
|
|
222
|
-
│ │
|
|
223
|
-
│ 4️⃣ 演進階段 │
|
|
224
|
-
│ └─ 新功能使用標準 TDD │
|
|
225
|
-
│ │
|
|
226
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
**工具支援**:
|
|
230
|
-
- ApprovalTests(多語言支援)
|
|
231
|
-
- Jest Snapshot Testing
|
|
232
|
-
- Python: pytest-snapshot
|
|
233
|
-
- AI 輔助測試輸入生成
|
|
234
|
-
|
|
235
|
-
### 決策樹
|
|
236
|
-
|
|
237
|
-
```
|
|
238
|
-
需求來源?
|
|
239
|
-
├─ 技術需求(效能、重構)→ TDD
|
|
240
|
-
├─ 業務需求
|
|
241
|
-
│ ├─ 有明確驗收標準?
|
|
242
|
-
│ │ ├─ 是 → ATDD → BDD → TDD
|
|
243
|
-
│ │ └─ 否 → BDD → TDD
|
|
244
|
-
│ └─ 複雜業務流程?
|
|
245
|
-
│ ├─ 是 → BDD(場景描述)→ TDD
|
|
246
|
-
│ └─ 否 → TDD
|
|
247
|
-
└─ 探索性/原型 → 暫時跳過 TDD
|
|
248
|
-
```
|
|
24
|
+
**完整指南: [TDD 指南](../methodologies/guides/tdd-guide.md)**
|
|
249
25
|
|
|
250
26
|
---
|
|
251
27
|
|
|
252
|
-
##
|
|
253
|
-
|
|
254
|
-
### 比較概覽
|
|
255
|
-
|
|
256
|
-
| 面向 | TDD | BDD | ATDD |
|
|
257
|
-
|------|-----|-----|------|
|
|
258
|
-
| **焦點** | 程式碼單元 | 行為 | 驗收標準 |
|
|
259
|
-
| **語言** | 程式碼 | 自然語言 (Gherkin) | 業務語言 |
|
|
260
|
-
| **參與者** | 開發者 | 開發者 + BA + QA | 全團隊 + 利益相關者 |
|
|
261
|
-
| **測試層級** | 單元/整合 | 功能/場景 | 系統/驗收 |
|
|
262
|
-
| **工具** | xUnit 框架 | Cucumber, Behave, SpecFlow | FitNesse, Concordion |
|
|
263
|
-
| **時機** | 編碼期間 | 編碼之前 | 開發開始之前 |
|
|
264
|
-
|
|
265
|
-
### 整合金字塔
|
|
266
|
-
|
|
267
|
-
```
|
|
268
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
269
|
-
│ 完整的測試驅動開發堆疊 │
|
|
270
|
-
├─────────────────────────────────────────────────────────────────┤
|
|
271
|
-
│ │
|
|
272
|
-
│ 需求層 ATDD - 驗收測試驅動開發 │
|
|
273
|
-
│ (接收業務驗收標準) │
|
|
274
|
-
│ ↓ │
|
|
275
|
-
│ 功能層 BDD - 行為驅動開發 │
|
|
276
|
-
│ (場景 → Step Definitions) │
|
|
277
|
-
│ ↓ │
|
|
278
|
-
│ 開發層 TDD - 測試驅動開發 │
|
|
279
|
-
│ (單元測試 → 程式碼) │
|
|
280
|
-
│ ↓ │
|
|
281
|
-
│ 整合層 整合與系統測試 │
|
|
282
|
-
│ │
|
|
283
|
-
│ 關鍵:ATDD → BDD → TDD → 整合測試(自上而下流程) │
|
|
284
|
-
│ │
|
|
285
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### BDD Gherkin 語法概覽
|
|
289
|
-
|
|
290
|
-
```gherkin
|
|
291
|
-
Feature: 使用者登入
|
|
292
|
-
作為一個註冊使用者
|
|
293
|
-
我想要登入我的帳號
|
|
294
|
-
以便我可以存取我的個人化內容
|
|
295
|
-
|
|
296
|
-
Scenario: 使用有效憑證成功登入
|
|
297
|
-
Given 我在登入頁面
|
|
298
|
-
And 我有一個註冊帳號,電子郵件為 "user@example.com"
|
|
299
|
-
When 我輸入電子郵件 "user@example.com"
|
|
300
|
-
And 我輸入密碼 "correctpassword"
|
|
301
|
-
And 我點擊登入按鈕
|
|
302
|
-
Then 我應該被重新導向到儀表板
|
|
303
|
-
And 我應該看到包含我名字的歡迎訊息
|
|
304
|
-
|
|
305
|
-
Scenario: 使用無效密碼登入失敗
|
|
306
|
-
Given 我在登入頁面
|
|
307
|
-
When 我輸入電子郵件 "user@example.com"
|
|
308
|
-
And 我輸入密碼 "wrongpassword"
|
|
309
|
-
And 我點擊登入按鈕
|
|
310
|
-
Then 我應該看到錯誤訊息 "無效的憑證"
|
|
311
|
-
And 我應該保持在登入頁面
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### ATDD 驗收標準格式
|
|
315
|
-
|
|
316
|
-
```markdown
|
|
317
|
-
## 功能:購物車結帳
|
|
318
|
-
|
|
319
|
-
### 驗收標準:
|
|
320
|
-
|
|
321
|
-
**AC-1:計算訂單總額**
|
|
322
|
-
- GIVEN 購物車中有價格為 [$10, $20, $15] 的商品
|
|
323
|
-
- WHEN 使用者進行結帳
|
|
324
|
-
- THEN 總額應為 $45
|
|
325
|
-
|
|
326
|
-
**AC-2:套用折扣碼**
|
|
327
|
-
- GIVEN 購物車總額為 $100
|
|
328
|
-
- AND 有效的折扣碼 "SAVE20" 為 20% 折扣
|
|
329
|
-
- WHEN 使用者套用折扣碼
|
|
330
|
-
- THEN 總額應為 $80
|
|
331
|
-
|
|
332
|
-
**AC-3:驗證最低訂單金額**
|
|
333
|
-
- GIVEN 購物車總額低於 $25
|
|
334
|
-
- WHEN 使用者嘗試結帳
|
|
335
|
-
- THEN 系統應顯示「最低訂單金額為 $25」錯誤
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
### 選擇正確的方法
|
|
339
|
-
|
|
340
|
-
| 使用案例 | 主要方法 | 輔助方法 |
|
|
341
|
-
|---------|---------|---------|
|
|
342
|
-
| 演算法實現 | TDD | - |
|
|
343
|
-
| 使用者驗證流程 | BDD | TDD |
|
|
344
|
-
| 支付處理 | ATDD | BDD + TDD |
|
|
345
|
-
| API 端點 | TDD | BDD 用於整合 |
|
|
346
|
-
| UI 組件 | BDD | TDD 用於邏輯 |
|
|
347
|
-
| 業務規則驗證 | ATDD | TDD |
|
|
348
|
-
| 效能優化 | TDD | - |
|
|
349
|
-
| 外部服務整合 | TDD | BDD 用於契約 |
|
|
350
|
-
|
|
351
|
-
---
|
|
352
|
-
|
|
353
|
-
## 與 SDD 整合
|
|
354
|
-
|
|
355
|
-
### SDD + TDD 統一工作流程
|
|
356
|
-
|
|
357
|
-
規格驅動開發 (SDD) 和測試驅動開發 (TDD) 是互補的:
|
|
358
|
-
|
|
359
|
-
- **SDD**:「規格優先,程式碼其次」- 定義要建構「什麼」
|
|
360
|
-
- **TDD**:「測試優先,程式碼其次」- 定義如何「驗證」
|
|
361
|
-
|
|
362
|
-
```
|
|
363
|
-
┌─────────────────────────────────────────────────────────────────────────────┐
|
|
364
|
-
│ SDD + TDD 整合工作流程 │
|
|
365
|
-
├─────────────────────────────────────────────────────────────────────────────┤
|
|
366
|
-
│ │
|
|
367
|
-
│ 1️⃣ SDD:提案階段 │
|
|
368
|
-
│ ├─ 撰寫 Spec:定義功能、驗收標準、邊界情況 │
|
|
369
|
-
│ ├─ 包含驗收標準(轉換為 ATDD 場景) │
|
|
370
|
-
│ └─ 取得利益相關者批准 │
|
|
371
|
-
│ (Spec ID: SPEC-001) │
|
|
372
|
-
│ │
|
|
373
|
-
│ 2️⃣ TDD:紅色階段 │
|
|
374
|
-
│ ├─ 基於 Spec 的驗收標準撰寫測試 │
|
|
375
|
-
│ ├─ 撰寫描述預期行為的失敗測試 │
|
|
376
|
-
│ ├─ 測試實現 Spec:一個標準 = 多個測試 │
|
|
377
|
-
│ └─ 在測試文件註解中參考 SPEC-001 │
|
|
378
|
-
│ │
|
|
379
|
-
│ 3️⃣ TDD:綠色 + 重構階段 │
|
|
380
|
-
│ ├─ 迭代開發,一次實現一個小功能 │
|
|
381
|
-
│ ├─ 測試通過後重構 │
|
|
382
|
-
│ └─ 保持所有 Spec 驗收標準測試通過 │
|
|
383
|
-
│ │
|
|
384
|
-
│ 4️⃣ SDD:驗證階段 │
|
|
385
|
-
│ ├─ 確認實現與 Spec 相符 │
|
|
386
|
-
│ ├─ 驗收測試套件通過 │
|
|
387
|
-
│ └─ 所有驗收標準已實現 ✓ │
|
|
388
|
-
│ │
|
|
389
|
-
│ 5️⃣ 提交 PR 和撰寫提交訊息 │
|
|
390
|
-
│ ├─ Commit: "feat(auth): implement login" │
|
|
391
|
-
│ ├─ Body: "Implements SPEC-001 with OAuth2" │
|
|
392
|
-
│ ├─ Refs: SPEC-001 │
|
|
393
|
-
│ └─ 包含測試覆蓋率報告 │
|
|
394
|
-
│ │
|
|
395
|
-
│ 6️⃣ SDD:歸檔階段 │
|
|
396
|
-
│ └─ 歸檔 Spec,連結到 PR/提交 │
|
|
397
|
-
│ │
|
|
398
|
-
└─────────────────────────────────────────────────────────────────────────────┘
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
### 將 Spec 驗收標準對應到 TDD 測試
|
|
402
|
-
|
|
403
|
-
| Spec 驗收標準 | TDD 測試 |
|
|
404
|
-
|--------------|----------|
|
|
405
|
-
| 「使用者可以用有效憑證登入」 | `test_login_with_valid_credentials_succeeds()` |
|
|
406
|
-
| 「無效密碼顯示錯誤」 | `test_login_with_invalid_password_shows_error()` |
|
|
407
|
-
| 「3 次失敗嘗試後帳號鎖定」 | `test_account_locks_after_three_failed_attempts()` |
|
|
408
|
-
| 「鎖定的帳號無法登入」 | `test_locked_account_cannot_login()` |
|
|
409
|
-
|
|
410
|
-
### 在測試中參考 Spec
|
|
411
|
-
|
|
412
|
-
```typescript
|
|
413
|
-
/**
|
|
414
|
-
* SPEC-001:使用者驗證 的測試
|
|
415
|
-
* @see specs/SPEC-001-user-authentication.md
|
|
416
|
-
*/
|
|
417
|
-
describe('使用者驗證 (SPEC-001)', () => {
|
|
418
|
-
// AC-1:使用者可以用有效憑證登入
|
|
419
|
-
test('should login successfully with valid credentials', async () => {
|
|
420
|
-
// ...
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
// AC-2:無效密碼顯示錯誤
|
|
424
|
-
test('should show error message for invalid password', async () => {
|
|
425
|
-
// ...
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
---
|
|
431
|
-
|
|
432
|
-
## TDD 工作流程
|
|
433
|
-
|
|
434
|
-
### 個人層級 TDD
|
|
435
|
-
|
|
436
|
-
```
|
|
437
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
438
|
-
│ 個人 TDD 工作階段流程 │
|
|
439
|
-
├─────────────────────────────────────────────────────────────────┤
|
|
440
|
-
│ │
|
|
441
|
-
│ 1. 理解需求 │
|
|
442
|
-
│ ├─ 閱讀 spec/使用者故事 │
|
|
443
|
-
│ └─ 識別驗收標準 │
|
|
444
|
-
│ │
|
|
445
|
-
│ 2. 列出測試案例(紙上或 TODO 註解) │
|
|
446
|
-
│ ├─ 快樂路徑場景 │
|
|
447
|
-
│ ├─ 邊界情況 │
|
|
448
|
-
│ ├─ 錯誤場景 │
|
|
449
|
-
│ └─ 邊界條件 │
|
|
450
|
-
│ │
|
|
451
|
-
│ 3. 選擇最簡單的測試案例 │
|
|
452
|
-
│ └─ 從最基本的快樂路徑開始 │
|
|
453
|
-
│ │
|
|
454
|
-
│ 4. 紅色:撰寫測試 │
|
|
455
|
-
│ ├─ 使用清晰的 Arrange-Act-Assert 撰寫測試 │
|
|
456
|
-
│ ├─ 使用描述性的測試名稱 │
|
|
457
|
-
│ └─ 執行測試,驗證它失敗 │
|
|
458
|
-
│ │
|
|
459
|
-
│ 5. 綠色:讓它通過 │
|
|
460
|
-
│ ├─ 撰寫最少的程式碼讓測試通過 │
|
|
461
|
-
│ ├─ 「假裝」是可以接受的 │
|
|
462
|
-
│ └─ 執行測試,驗證它通過 │
|
|
463
|
-
│ │
|
|
464
|
-
│ 6. 重構:清理 │
|
|
465
|
-
│ ├─ 消除重複 │
|
|
466
|
-
│ ├─ 改善命名 │
|
|
467
|
-
│ ├─ 提取方法/函式 │
|
|
468
|
-
│ └─ 每次變更後執行所有測試 │
|
|
469
|
-
│ │
|
|
470
|
-
│ 7. 從步驟 3 重複,直到所有測試完成 │
|
|
471
|
-
│ │
|
|
472
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
### 團隊層級 TDD
|
|
476
|
-
|
|
477
|
-
#### 使用 TDD 的結對程式設計
|
|
478
|
-
|
|
479
|
-
**乒乓模式**:
|
|
480
|
-
1. 開發者 A 撰寫一個失敗的測試
|
|
481
|
-
2. 開發者 B 撰寫程式碼讓測試通過
|
|
482
|
-
3. 開發者 B 撰寫下一個失敗的測試
|
|
483
|
-
4. 開發者 A 撰寫程式碼讓測試通過
|
|
484
|
-
5. 任一開發者可以隨時重構
|
|
485
|
-
6. 重複
|
|
486
|
-
|
|
487
|
-
**駕駛員-領航員模式**:
|
|
488
|
-
1. 領航員思考設計和測試案例
|
|
489
|
-
2. 駕駛員撰寫測試和程式碼
|
|
490
|
-
3. 每 15-30 分鐘交換角色
|
|
491
|
-
|
|
492
|
-
#### 使用 TDD 的群體程式設計
|
|
493
|
-
|
|
494
|
-
- 一個駕駛員(打字),多個領航員(指導)
|
|
495
|
-
- 每 5-10 分鐘輪換駕駛員
|
|
496
|
-
- 集體決定測試案例和實現
|
|
497
|
-
- 透過多元視角獲得更高品質
|
|
498
|
-
|
|
499
|
-
### CI/CD 整合
|
|
500
|
-
|
|
501
|
-
```yaml
|
|
502
|
-
# TDD 的 GitHub Actions 工作流程範例
|
|
503
|
-
name: TDD CI Pipeline
|
|
504
|
-
|
|
505
|
-
on: [push, pull_request]
|
|
506
|
-
|
|
507
|
-
jobs:
|
|
508
|
-
test:
|
|
509
|
-
runs-on: ubuntu-latest
|
|
510
|
-
steps:
|
|
511
|
-
- uses: actions/checkout@v4
|
|
512
|
-
|
|
513
|
-
- name: Setup Node.js
|
|
514
|
-
uses: actions/setup-node@v4
|
|
515
|
-
with:
|
|
516
|
-
node-version: '20'
|
|
517
|
-
|
|
518
|
-
- name: Install dependencies
|
|
519
|
-
run: npm ci
|
|
520
|
-
|
|
521
|
-
- name: Run unit tests
|
|
522
|
-
run: npm run test:unit
|
|
523
|
-
|
|
524
|
-
- name: Run integration tests
|
|
525
|
-
run: npm run test:integration
|
|
526
|
-
|
|
527
|
-
- name: Check coverage threshold
|
|
528
|
-
run: npm run test:coverage -- --coverage-threshold=80
|
|
529
|
-
|
|
530
|
-
- name: Upload coverage report
|
|
531
|
-
uses: codecov/codecov-action@v4
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
---
|
|
535
|
-
|
|
536
|
-
## 測試設計指南
|
|
537
|
-
|
|
538
|
-
### AAA 模式(Arrange-Act-Assert)
|
|
539
|
-
|
|
540
|
-
```typescript
|
|
541
|
-
test('should calculate total with discount', () => {
|
|
542
|
-
// Arrange - 設置測試資料和依賴
|
|
543
|
-
const cart = new ShoppingCart();
|
|
544
|
-
cart.addItem({ name: 'Widget', price: 100 });
|
|
545
|
-
cart.setDiscountCode('SAVE20'); // 20% 折扣
|
|
546
|
-
|
|
547
|
-
// Act - 執行被測試的行為
|
|
548
|
-
const total = cart.calculateTotal();
|
|
549
|
-
|
|
550
|
-
// Assert - 驗證結果
|
|
551
|
-
expect(total).toBe(80);
|
|
552
|
-
});
|
|
553
|
-
```
|
|
28
|
+
## 快速參考
|
|
554
29
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
```typescript
|
|
558
|
-
test('given a cart with items, when discount applied, then total is reduced', () => {
|
|
559
|
-
// Given
|
|
560
|
-
const cart = new ShoppingCart();
|
|
561
|
-
cart.addItem({ name: 'Widget', price: 100 });
|
|
562
|
-
|
|
563
|
-
// When
|
|
564
|
-
cart.applyDiscount('SAVE20');
|
|
565
|
-
const total = cart.calculateTotal();
|
|
566
|
-
|
|
567
|
-
// Then
|
|
568
|
-
expect(total).toBe(80);
|
|
569
|
-
});
|
|
570
|
-
```
|
|
571
|
-
|
|
572
|
-
### 測試命名慣例
|
|
573
|
-
|
|
574
|
-
| 模式 | 範例 |
|
|
575
|
-
|------|------|
|
|
576
|
-
| `should_[行為]_when_[條件]` | `should_return_error_when_email_invalid` |
|
|
577
|
-
| `[方法]_[場景]_[預期]` | `calculateTotal_withDiscount_returnsReducedPrice` |
|
|
578
|
-
| `test_[方法]_[場景]_[預期]` | `test_login_invalidPassword_throwsError` |
|
|
579
|
-
| `it_[做某事]` | `it_calculates_total_correctly` |
|
|
580
|
-
|
|
581
|
-
### 測試資料最佳實踐
|
|
582
|
-
|
|
583
|
-
```typescript
|
|
584
|
-
// ✅ 好:清晰、有意義的測試資料
|
|
585
|
-
const validUser = {
|
|
586
|
-
email: 'john.doe@example.com',
|
|
587
|
-
password: 'SecureP@ss123',
|
|
588
|
-
role: 'admin'
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// ❌ 差:沒有上下文的魔術字串
|
|
592
|
-
const user = {
|
|
593
|
-
email: 'a@b.c',
|
|
594
|
-
password: '123',
|
|
595
|
-
role: 'x'
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
// ✅ 好:使用測試資料建構器
|
|
599
|
-
const user = UserBuilder.create()
|
|
600
|
-
.withEmail('john.doe@example.com')
|
|
601
|
-
.withRole('admin')
|
|
602
|
-
.build();
|
|
603
|
-
|
|
604
|
-
// ✅ 好:使用常數表示邊界值
|
|
605
|
-
const MAX_PASSWORD_LENGTH = 128;
|
|
606
|
-
const MIN_PASSWORD_LENGTH = 8;
|
|
607
|
-
|
|
608
|
-
test('should reject password exceeding max length', () => {
|
|
609
|
-
const longPassword = 'a'.repeat(MAX_PASSWORD_LENGTH + 1);
|
|
610
|
-
expect(() => validatePassword(longPassword)).toThrow();
|
|
611
|
-
});
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
### 測試邊界情況
|
|
615
|
-
|
|
616
|
-
確保測試涵蓋 [測試完整性維度](test-completeness-dimensions.md) 的所有七個維度:
|
|
617
|
-
|
|
618
|
-
1. **快樂路徑** - 正常預期行為
|
|
619
|
-
2. **邊界條件** - 最小/最大值、限制
|
|
620
|
-
3. **錯誤處理** - 無效輸入、例外
|
|
621
|
-
4. **授權** - 角色為基礎的存取控制
|
|
622
|
-
5. **狀態變化** - 前後驗證
|
|
623
|
-
6. **驗證** - 格式、業務規則
|
|
624
|
-
7. **整合** - 真實查詢驗證
|
|
625
|
-
|
|
626
|
-
---
|
|
627
|
-
|
|
628
|
-
## 重構策略
|
|
629
|
-
|
|
630
|
-
### 何時重構
|
|
631
|
-
|
|
632
|
-
當你看到以下情況時進行重構:
|
|
633
|
-
|
|
634
|
-
- **重複**:相同的程式碼出現在多個地方
|
|
635
|
-
- **過長方法**:函式做太多事
|
|
636
|
-
- **命名不佳**:不清楚的變數/函式名稱
|
|
637
|
-
- **複雜條件**:巢狀的 if/else 鏈
|
|
638
|
-
- **功能嫉妒**:方法過度使用另一個類別的資料
|
|
639
|
-
- **資料團塊**:相同的資料群組一起出現
|
|
640
|
-
|
|
641
|
-
### 安全重構檢查清單
|
|
642
|
-
|
|
643
|
-
```
|
|
644
|
-
重構前:
|
|
645
|
-
□ 所有測試都通過(綠色)
|
|
646
|
-
□ 有足夠的測試覆蓋
|
|
647
|
-
□ 你理解程式碼在做什麼
|
|
648
|
-
|
|
649
|
-
重構中:
|
|
650
|
-
□ 一次只做「一個」小變更
|
|
651
|
-
□ 「每次」變更後執行測試
|
|
652
|
-
□ 如果測試失敗,立即復原
|
|
653
|
-
□ 重構時不要新增功能
|
|
654
|
-
|
|
655
|
-
重構後:
|
|
656
|
-
□ 所有測試仍然通過
|
|
657
|
-
□ 程式碼更乾淨/簡單
|
|
658
|
-
□ 沒有新增功能
|
|
659
|
-
```
|
|
660
|
-
|
|
661
|
-
### 常見重構技術
|
|
662
|
-
|
|
663
|
-
| 技術 | 使用時機 | 範例 |
|
|
664
|
-
|------|---------|------|
|
|
665
|
-
| **提取方法** | 過長方法、重複程式碼 | 提取 10 行到 `calculateDiscount()` |
|
|
666
|
-
| **重新命名** | 不清楚的名稱 | `calc()` → `calculateOrderTotal()` |
|
|
667
|
-
| **內聯** | 過度抽象 | 移除不必要的包裝函式 |
|
|
668
|
-
| **提取變數** | 複雜表達式 | `const isEligible = age >= 18 && hasLicense` |
|
|
669
|
-
| **用多型取代條件** | 複雜的 switch/if 鏈 | 使用策略模式 |
|
|
670
|
-
| **引入參數物件** | 太多參數 | `(x, y, width, height)` → `Rectangle rect` |
|
|
671
|
-
|
|
672
|
-
### 程式碼異味目錄
|
|
673
|
-
|
|
674
|
-
根據 Martin Fowler 的《Refactoring》(第二版),程式碼異味分為五大類別:
|
|
675
|
-
|
|
676
|
-
#### 1. 膨脹型(Bloaters)
|
|
677
|
-
|
|
678
|
-
| 異味 | 說明 | 重構方式 |
|
|
679
|
-
|------|------|---------|
|
|
680
|
-
| **Long Method(過長方法)** | 方法超過 20 行,做太多事 | Extract Method、Replace Temp with Query、Introduce Parameter Object、Preserve Whole Object、Replace Method with Method Object |
|
|
681
|
-
| **Large Class(過大類別)** | 類別有太多職責 | Extract Class、Extract Subclass、Extract Interface、Duplicate Observed Data |
|
|
682
|
-
| **Primitive Obsession(基本型別偏執)** | 過度使用基本型別而非小物件 | Replace Data Value with Object、Replace Type Code with Class/Subclass/Strategy、Extract Class、Introduce Parameter Object |
|
|
683
|
-
| **Long Parameter List(過長參數列表)** | 方法有太多參數(>3-4 個) | Replace Parameter with Method Call、Preserve Whole Object、Introduce Parameter Object |
|
|
684
|
-
| **Data Clumps(資料泥團)** | 相同的資料群組一起出現 | Extract Class、Introduce Parameter Object、Preserve Whole Object |
|
|
685
|
-
|
|
686
|
-
#### 2. 物件導向濫用者(OO Abusers)
|
|
687
|
-
|
|
688
|
-
| 異味 | 說明 | 重構方式 |
|
|
689
|
-
|------|------|---------|
|
|
690
|
-
| **Switch Statements(Switch 語句)** | 複雜的 switch/case 或 if/else 鏈 | Replace Type Code with Subclasses、Replace Conditional with Polymorphism、Replace Parameter with Explicit Methods、Introduce Null Object |
|
|
691
|
-
| **Temporary Field(暫時欄位)** | 只在某些情況下有值的欄位 | Extract Class、Introduce Null Object |
|
|
692
|
-
| **Refused Bequest(被拒絕的遺產)** | 子類別不使用繼承的方法/資料 | Replace Inheritance with Delegation、Push Down Method/Field |
|
|
693
|
-
| **Alternative Classes with Different Interfaces(介面不同的替代類別)** | 做相同事情但有不同介面的類別 | Rename Method、Move Method、Extract Superclass |
|
|
694
|
-
| **Parallel Inheritance Hierarchies(平行繼承階層)** | 每次建立一個類別的子類別就需要建立另一個類別的子類別 | Move Method、Move Field 合併階層 |
|
|
695
|
-
|
|
696
|
-
#### 3. 變更阻礙者(Change Preventers)
|
|
697
|
-
|
|
698
|
-
| 異味 | 說明 | 重構方式 |
|
|
699
|
-
|------|------|---------|
|
|
700
|
-
| **Divergent Change(發散式變更)** | 一個類別因不同原因經常被修改 | Extract Class 分離不同的關注點 |
|
|
701
|
-
| **Shotgun Surgery(散彈槍手術)** | 一個變更需要修改多個類別 | Move Method、Move Field、Inline Class 合併相關行為 |
|
|
702
|
-
| **Parallel Inheritance Hierarchies(平行繼承階層)** | 每次建立一個類別的子類別就需要建立另一個 | Move Method、Move Field |
|
|
703
|
-
|
|
704
|
-
#### 4. 可有可無者(Dispensables)
|
|
705
|
-
|
|
706
|
-
| 異味 | 說明 | 重構方式 |
|
|
707
|
-
|------|------|---------|
|
|
708
|
-
| **Lazy Class(懶惰類別)** | 做太少事的類別 | Inline Class、Collapse Hierarchy |
|
|
709
|
-
| **Data Class(資料類別)** | 只有欄位和 getter/setter 的類別 | Move Method、Encapsulate Field、Encapsulate Collection |
|
|
710
|
-
| **Duplicate Code(重複程式碼)** | 相同程式碼在多處出現 | Extract Method、Extract Class、Pull Up Method、Form Template Method |
|
|
711
|
-
| **Dead Code(死碼)** | 未使用的程式碼 | 刪除未使用的程式碼 |
|
|
712
|
-
| **Speculative Generality(推測式通用性)** | 為「未來可能需要」建立的未使用抽象 | Collapse Hierarchy、Inline Class、Remove Parameter、Rename Method |
|
|
713
|
-
| **Comments(註解)** | 用於解釋難懂程式碼的過多註解 | Extract Method、Rename Method、Introduce Assertion(讓程式碼自我說明) |
|
|
714
|
-
|
|
715
|
-
#### 5. 耦合者(Couplers)
|
|
716
|
-
|
|
717
|
-
| 異味 | 說明 | 重構方式 |
|
|
718
|
-
|------|------|---------|
|
|
719
|
-
| **Feature Envy(功能嫉妒)** | 方法過度使用另一個類別的資料 | Move Method、Extract Method |
|
|
720
|
-
| **Inappropriate Intimacy(不當親密)** | 類別過度存取彼此的內部 | Move Method、Move Field、Change Bidirectional to Unidirectional、Extract Class、Hide Delegate |
|
|
721
|
-
| **Message Chains(訊息鏈)** | 一連串的 getThis().getThat().getOther() | Hide Delegate、Extract Method、Move Method |
|
|
722
|
-
| **Middle Man(中間人)** | 類別的大部分方法只是委派給另一個類別 | Remove Middle Man、Inline Method、Replace Delegation with Inheritance |
|
|
723
|
-
| **Incomplete Library Class(不完整的函式庫類別)** | 函式庫類別缺少你需要的功能 | Introduce Foreign Method、Introduce Local Extension |
|
|
724
|
-
|
|
725
|
-
#### 快速診斷表
|
|
726
|
-
|
|
727
|
-
```
|
|
728
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
729
|
-
│ 程式碼異味快速診斷 │
|
|
730
|
-
├─────────────────────────────────────────────────────────────────┤
|
|
731
|
-
│ │
|
|
732
|
-
│ 症狀 可能的異味 │
|
|
733
|
-
│ ───────────────────────────────────────────── │
|
|
734
|
-
│ 方法太長(>20 行) Long Method │
|
|
735
|
-
│ 類別太大(>200 行) Large Class │
|
|
736
|
-
│ 太多參數(>4 個) Long Parameter List │
|
|
737
|
-
│ 重複程式碼 Duplicate Code │
|
|
738
|
-
│ 複雜的 if/else 或 switch Switch Statements │
|
|
739
|
-
│ 過度使用基本型別 Primitive Obsession │
|
|
740
|
-
│ 一個變更影響多處 Shotgun Surgery │
|
|
741
|
-
│ 一個類別因多種原因變更 Divergent Change │
|
|
742
|
-
│ 方法使用別的類別資料 Feature Envy │
|
|
743
|
-
│ 長串的方法呼叫 Message Chains │
|
|
744
|
-
│ 類別只委派給另一個類別 Middle Man │
|
|
745
|
-
│ 只有 getter/setter 的類別 Data Class │
|
|
746
|
-
│ 未使用的程式碼或類別 Dead Code / Lazy Class │
|
|
747
|
-
│ 解釋程式碼的大量註解 Comments │
|
|
748
|
-
│ │
|
|
749
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
750
|
-
```
|
|
751
|
-
|
|
752
|
-
---
|
|
753
|
-
|
|
754
|
-
## TDD 中的測試替身
|
|
755
|
-
|
|
756
|
-
### 測試替身類型
|
|
757
|
-
|
|
758
|
-
| 類型 | 目的 | 使用時機 |
|
|
759
|
-
|------|------|---------|
|
|
760
|
-
| **Dummy** | 填充參數列表 | 必要參數但測試中未使用 |
|
|
761
|
-
| **Stub** | 回傳預定義的值 | 模擬特定場景 |
|
|
762
|
-
| **Spy** | 記錄互動 | 驗證方法是否被呼叫 |
|
|
763
|
-
| **Mock** | 驗證互動 + 回傳值 | 測試行為和協作 |
|
|
764
|
-
| **Fake** | 簡化的實作 | 記憶體內資料庫 |
|
|
765
|
-
|
|
766
|
-
### 依測試層級的測試替身使用
|
|
767
|
-
|
|
768
|
-
| 層級 | 建議的替身 |
|
|
769
|
-
|------|-----------|
|
|
770
|
-
| **單元測試** | 所有外部依賴使用 Mock、Stub |
|
|
771
|
-
| **整合測試** | DB 使用 Fake,外部 API 使用 Stub |
|
|
772
|
-
| **系統測試** | 真實元件,只有外部服務使用 Fake |
|
|
773
|
-
| **E2E 測試** | 全部使用真實 |
|
|
774
|
-
|
|
775
|
-
### 範例:使用 Mock 和 Stub
|
|
776
|
-
|
|
777
|
-
```typescript
|
|
778
|
-
// Stub 範例 - 預定義的回傳值
|
|
779
|
-
const paymentGateway = {
|
|
780
|
-
processPayment: jest.fn().mockResolvedValue({ success: true, transactionId: 'TXN123' })
|
|
781
|
-
};
|
|
782
|
-
|
|
783
|
-
// Mock 範例 - 驗證互動
|
|
784
|
-
const emailService = {
|
|
785
|
-
sendConfirmation: jest.fn()
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
test('should send confirmation email after successful payment', async () => {
|
|
789
|
-
const order = new OrderService(paymentGateway, emailService);
|
|
790
|
-
|
|
791
|
-
await order.checkout({ amount: 100, email: 'user@example.com' });
|
|
792
|
-
|
|
793
|
-
// 驗證 mock 是否使用正確的參數被呼叫
|
|
794
|
-
expect(emailService.sendConfirmation).toHaveBeenCalledWith(
|
|
795
|
-
'user@example.com',
|
|
796
|
-
expect.objectContaining({ transactionId: 'TXN123' })
|
|
797
|
-
);
|
|
798
|
-
});
|
|
799
|
-
```
|
|
800
|
-
|
|
801
|
-
### 避免過度 Mock
|
|
802
|
-
|
|
803
|
-
```
|
|
804
|
-
❌ 過度 mock(測試實作細節):
|
|
805
|
-
- Mock 私有方法
|
|
806
|
-
- Mock 每一個依賴
|
|
807
|
-
- 驗證每一個內部方法呼叫
|
|
808
|
-
|
|
809
|
-
✅ 適當的 mock:
|
|
810
|
-
- Mock 外部服務(API、資料庫)
|
|
811
|
-
- Mock 慢速操作(檔案 I/O、網路)
|
|
812
|
-
- Mock 非確定性操作(時間、隨機)
|
|
813
|
-
```
|
|
814
|
-
|
|
815
|
-
---
|
|
816
|
-
|
|
817
|
-
## 反模式與修復
|
|
818
|
-
|
|
819
|
-
### 程式碼層級反模式
|
|
820
|
-
|
|
821
|
-
| 反模式 | 說明 | 影響 | 修復方式 |
|
|
822
|
-
|--------|------|------|---------|
|
|
823
|
-
| **測試實作細節** | 測試私有方法或內部狀態 | 脆弱的測試,重構會破壞測試 | 只測試公開行為 |
|
|
824
|
-
| **過度 Mock** | Mock 所有東西,失去真實性 | 虛假的信心,bug 進入生產環境 | 平衡 mock 和真實元件 |
|
|
825
|
-
| **測試相依性** | 測試依賴執行順序 | 隨機失敗,難以隔離 | 每個測試設置自己的狀態 |
|
|
826
|
-
| **魔術數字/字串** | 沒有意義的硬編碼值 | 可讀性差,維護噩夢 | 使用命名常數、建構器 |
|
|
827
|
-
| **缺少斷言** | 測試沒有適當的斷言 | 假陽性 | 每個測試需要明確的斷言 |
|
|
828
|
-
| **不穩定測試** | 有時通過,有時失敗 | 對測試套件信任度降低 | 消除時間/順序依賴 |
|
|
829
|
-
| **過大的 Arrange 區塊** | 每個測試都有複雜設置 | 難以理解、維護 | 提取設置到建構器/fixtures |
|
|
830
|
-
| **測試中的條件邏輯** | 測試程式碼中的 if/else | 一個測試中有多個測試 | 分割成獨立的測試 |
|
|
831
|
-
| **測試程式碼重複** | 許多測試中相同的設置 | 維護負擔 | 提取共享設置 |
|
|
832
|
-
| **過於特定的斷言** | 斷言每一個欄位 | 脆弱的測試 | 只斷言相關欄位 |
|
|
833
|
-
| **忽略測試失敗** | 跳過或註解掉失敗的測試 | 隱藏的 bug | 修復或移除失敗的測試 |
|
|
834
|
-
| **測試第三方程式碼** | 測試程式庫/框架行為 | 浪費努力 | 信任第三方,測試你的程式碼 |
|
|
835
|
-
| **一個巨大的測試** | 單一測試涵蓋所有 | 難以診斷失敗 | 分割成聚焦的測試 |
|
|
836
|
-
| **沒有測試名稱** | `test1`、`test2` | 無法理解 | 使用描述性名稱 |
|
|
837
|
-
| **捕獲所有例外** | 測試中的 `catch (Exception e)` | 隱藏的失敗 | 捕獲特定例外 |
|
|
838
|
-
|
|
839
|
-
### 流程層級反模式
|
|
840
|
-
|
|
841
|
-
| 反模式 | 說明 | 影響 | 修復方式 |
|
|
842
|
-
|--------|------|------|---------|
|
|
843
|
-
| **跳過紅色階段** | 在測試之前寫程式碼 | 失去 TDD 設計優點 | 紀律:始終先寫失敗的測試 |
|
|
844
|
-
| **跳過重構階段** | 從不清理 | 技術債累積 | 安排重構時間 |
|
|
845
|
-
| **開發後測試 (TAD)** | 程式碼完成後才寫測試 | 不是 TDD,錯過設計回饋 | 真正的 TDD:測試優先 |
|
|
846
|
-
| **一次寫所有測試** | 同時寫所有測試 | 不堪負荷,覆蓋率差 | 一次一個測試 |
|
|
847
|
-
| **100% 覆蓋率迷思** | 追求覆蓋率指標 | 無意義的測試 | 專注於行為覆蓋 |
|
|
848
|
-
| **不審查測試** | PR 中不審查測試 | 測試品質差 | 在程式碼審查中包含測試 |
|
|
849
|
-
| **延遲執行測試** | 不常執行測試 | 回饋延遲 | 持續執行測試 |
|
|
850
|
-
| **忽略慢速測試** | 讓測試套件變慢 | 開發者跳過測試 | 優化或並行化 |
|
|
851
|
-
| **TDD 狂熱** | 到處強制使用 TDD | 團隊挫敗 | 務實地應用 TDD |
|
|
852
|
-
| **不維護測試** | 讓測試腐敗 | 假陽性/假陰性 | 將測試視為生產程式碼 |
|
|
853
|
-
|
|
854
|
-
### 診斷與修復步驟
|
|
855
|
-
|
|
856
|
-
```
|
|
857
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
858
|
-
│ 反模式診斷工作流程 │
|
|
859
|
-
├─────────────────────────────────────────────────────────────────┤
|
|
860
|
-
│ │
|
|
861
|
-
│ 症狀:重構時測試經常失敗 │
|
|
862
|
-
│ ├─ 可能原因:測試實作細節 │
|
|
863
|
-
│ └─ 修復:審查測試,確保只測試行為 │
|
|
864
|
-
│ │
|
|
865
|
-
│ 症狀:測試通過但 bug 進入生產環境 │
|
|
866
|
-
│ ├─ 可能原因:過度 mock,缺少邊界情況 │
|
|
867
|
-
│ └─ 修復:新增整合測試,審查覆蓋差距 │
|
|
868
|
-
│ │
|
|
869
|
-
│ 症狀:測試隨機失敗 │
|
|
870
|
-
│ ├─ 可能原因:測試相依性,時間問題 │
|
|
871
|
-
│ └─ 修復:隔離測試,mock 時間相關操作 │
|
|
872
|
-
│ │
|
|
873
|
-
│ 症狀:測試套件執行時間太長 │
|
|
874
|
-
│ ├─ 可能原因:整合測試太多,慢速 I/O │
|
|
875
|
-
│ └─ 修復:增加單元測試比例,並行化 │
|
|
876
|
-
│ │
|
|
877
|
-
│ 症狀:團隊迴避寫測試 │
|
|
878
|
-
│ ├─ 可能原因:測試太複雜,工具不佳 │
|
|
879
|
-
│ └─ 修復:簡化測試設置,改善測試工具 │
|
|
880
|
-
│ │
|
|
881
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
882
|
-
```
|
|
883
|
-
|
|
884
|
-
---
|
|
885
|
-
|
|
886
|
-
## 語言/框架實踐
|
|
887
|
-
|
|
888
|
-
詳細的語言特定 TDD 範例,請參閱 TDD Assistant skill:
|
|
889
|
-
- [語言範例](../skills/claude-code/tdd-assistant/language-examples.md)
|
|
890
|
-
|
|
891
|
-
### 依語言快速參考
|
|
892
|
-
|
|
893
|
-
| 語言 | 測試框架 | Mock 程式庫 | BDD 工具 |
|
|
894
|
-
|------|---------|------------|---------|
|
|
895
|
-
| **JavaScript/TypeScript** | Jest, Vitest | jest.mock, vitest.mock | Cucumber.js |
|
|
896
|
-
| **Python** | pytest, unittest | unittest.mock, pytest-mock | Behave |
|
|
897
|
-
| **C#** | xUnit, NUnit, MSTest | Moq, NSubstitute | SpecFlow |
|
|
898
|
-
| **Java** | JUnit 5, TestNG | Mockito, EasyMock | Cucumber-JVM |
|
|
899
|
-
| **Go** | testing | testify/mock | godog |
|
|
900
|
-
| **Ruby** | RSpec, minitest | rspec-mocks | Cucumber |
|
|
901
|
-
|
|
902
|
-
### 框架選擇指南
|
|
903
|
-
|
|
904
|
-
| 考量 | 建議 |
|
|
30
|
+
| 面向 | 說明 |
|
|
905
31
|
|------|------|
|
|
906
|
-
|
|
|
907
|
-
|
|
|
908
|
-
|
|
|
909
|
-
|
|
|
910
|
-
|
|
|
911
|
-
|
|
912
|
-
---
|
|
913
|
-
|
|
914
|
-
## 度量與評估
|
|
915
|
-
|
|
916
|
-
### TDD 成熟度模型
|
|
917
|
-
|
|
918
|
-
| 層級 | 名稱 | 特徵 |
|
|
919
|
-
|------|------|------|
|
|
920
|
-
| **Level 0** | 無 TDD | 程式碼之後寫測試(如果有的話) |
|
|
921
|
-
| **Level 1** | 測試優先 | 有時在程式碼之前寫測試 |
|
|
922
|
-
| **Level 2** | TDD 實踐者 | 一致的紅-綠-重構循環 |
|
|
923
|
-
| **Level 3** | TDD 專家 | 有效的測試替身,乾淨的測試 |
|
|
924
|
-
| **Level 4** | TDD 大師 | TDD 驅動設計,指導他人 |
|
|
925
|
-
|
|
926
|
-
### 關鍵指標
|
|
927
|
-
|
|
928
|
-
| 指標 | 目標 | 警示閾值 |
|
|
929
|
-
|------|------|---------|
|
|
930
|
-
| **程式碼覆蓋率** | > 80% | < 60% |
|
|
931
|
-
| **測試對程式碼比** | 1:1 到 2:1 | < 0.5:1 |
|
|
932
|
-
| **測試執行時間** | < 30 秒(單元) | > 2 分鐘 |
|
|
933
|
-
| **不穩定測試率** | 0% | > 1% |
|
|
934
|
-
| **測試維護成本** | < 15% 開發時間 | > 30% |
|
|
935
|
-
| **缺陷逃逸率** | 下降中 | 上升中 |
|
|
936
|
-
|
|
937
|
-
### 評估檢查清單
|
|
938
|
-
|
|
939
|
-
```
|
|
940
|
-
團隊 TDD 評估:
|
|
941
|
-
|
|
942
|
-
□ 在生產程式碼之前寫測試
|
|
943
|
-
□ 遵循紅-綠-重構循環
|
|
944
|
-
□ 測試名稱清楚描述行為
|
|
945
|
-
□ 測試是獨立且可重複的
|
|
946
|
-
□ 測試套件執行快速(< 2 分鐘)
|
|
947
|
-
□ 沒有不穩定的測試
|
|
948
|
-
□ 足夠的覆蓋率(> 80%)
|
|
949
|
-
□ 程式碼審查中審查測試
|
|
950
|
-
□ 定期進行重構
|
|
951
|
-
□ CI/CD 自動執行測試
|
|
952
|
-
```
|
|
953
|
-
|
|
954
|
-
---
|
|
32
|
+
| **核心循環** | 紅 → 綠 → 重構 → 重複 |
|
|
33
|
+
| **FIRST 原則** | 快速 (Fast)、獨立 (Independent)、可重複 (Repeatable)、自我驗證 (Self-validating)、及時 (Timely) |
|
|
34
|
+
| **測試層級** | 單元/整合測試 |
|
|
35
|
+
| **參與者** | 開發人員 |
|
|
36
|
+
| **工具** | xUnit 框架 (Jest, pytest, JUnit 等) |
|
|
955
37
|
|
|
956
38
|
## 相關標準
|
|
957
39
|
|
|
958
|
-
- [
|
|
959
|
-
- [
|
|
960
|
-
- [測試完整性維度](test-completeness-dimensions.md) - 7 維度框架
|
|
961
|
-
- [規格驅動開發](spec-driven-development.md) - SDD 工作流程
|
|
962
|
-
- [程式碼入庫標準](checkin-standards.md) - 入庫要求
|
|
963
|
-
- [程式碼審查檢查清單](code-review-checklist.md) - 審查指南
|
|
964
|
-
|
|
965
|
-
---
|
|
966
|
-
|
|
967
|
-
## 參考資料
|
|
968
|
-
|
|
969
|
-
### 書籍
|
|
970
|
-
|
|
971
|
-
- Kent Beck - "Test Driven Development: By Example" (2002)
|
|
972
|
-
- Robert C. Martin - "Clean Code" 第 9 章:單元測試 (2008)
|
|
973
|
-
- Michael Feathers - "Working Effectively with Legacy Code" (2004)
|
|
974
|
-
- Steve Freeman & Nat Pryce - "Growing Object-Oriented Software, Guided by Tests" (2009)
|
|
975
|
-
|
|
976
|
-
### 標準
|
|
977
|
-
|
|
978
|
-
- [IEEE 29119 - 軟體測試標準](https://www.iso.org/standard/81291.html)
|
|
979
|
-
- [SWEBOK v4.0 - 第 5 章:軟體建構](https://www.computer.org/education/bodies-of-knowledge/software-engineering)
|
|
980
|
-
- [ISTQB 認證測試員基礎級](https://www.istqb.org/)
|
|
981
|
-
|
|
982
|
-
### 線上資源
|
|
983
|
-
|
|
984
|
-
- [TDD by Example - Martin Fowler](https://martinfowler.com/bliki/TestDrivenDevelopment.html)
|
|
985
|
-
- [The Three Rules of TDD - Uncle Bob](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd)
|
|
986
|
-
- [Test Pyramid - Martin Fowler](https://martinfowler.com/bliki/TestPyramid.html)
|
|
987
|
-
- [Approval Tests](https://approvaltests.com/)
|
|
988
|
-
|
|
989
|
-
---
|
|
990
|
-
|
|
991
|
-
## 版本歷史
|
|
992
|
-
|
|
993
|
-
| 版本 | 日期 | 變更 |
|
|
994
|
-
|------|------|------|
|
|
995
|
-
| 1.1.0 | 2026-01-12 | 新增:完整程式碼異味目錄(22+ 種異味,分為 5 大類別),基於 Martin Fowler《Refactoring》第二版 |
|
|
996
|
-
| 1.0.0 | 2026-01-07 | 初始 TDD 標準定義 |
|
|
997
|
-
|
|
998
|
-
---
|
|
999
|
-
|
|
1000
|
-
## 授權
|
|
1001
|
-
|
|
1002
|
-
本標準依據 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 授權釋出。
|
|
1003
|
-
|
|
1004
|
-
**來源**: [universal-dev-standards](https://github.com/AsiaOstrich/universal-dev-standards)
|
|
40
|
+
- [測試標準](testing-standards.md)
|
|
41
|
+
- [規格驅動開發](spec-driven-development.md)
|