universal-dev-standards 3.5.1-beta.1 → 3.5.1-beta.11

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.
Files changed (433) hide show
  1. package/bin/uds.js +2 -0
  2. package/bundled/core/ai-instruction-standards.md +205 -0
  3. package/bundled/core/anti-hallucination.md +684 -0
  4. package/bundled/core/changelog-standards.md +556 -0
  5. package/bundled/core/checkin-standards.md +935 -0
  6. package/bundled/core/code-review-checklist.md +684 -0
  7. package/bundled/core/commit-message-guide.md +915 -0
  8. package/bundled/core/documentation-structure.md +1117 -0
  9. package/bundled/core/documentation-writing-standards.md +487 -0
  10. package/bundled/core/error-code-standards.md +382 -0
  11. package/bundled/core/git-workflow.md +859 -0
  12. package/bundled/core/logging-standards.md +323 -0
  13. package/bundled/core/project-structure.md +354 -0
  14. package/bundled/core/refactoring-standards.md +636 -0
  15. package/bundled/core/spec-driven-development.md +207 -0
  16. package/bundled/core/test-completeness-dimensions.md +536 -0
  17. package/bundled/core/test-driven-development.md +995 -0
  18. package/bundled/core/testing-standards.md +3061 -0
  19. package/bundled/core/versioning.md +902 -0
  20. package/bundled/locales/README.md +88 -0
  21. package/bundled/locales/zh-CN/CHANGELOG.md +705 -0
  22. package/bundled/locales/zh-CN/CLAUDE.md +213 -0
  23. package/bundled/locales/zh-CN/MAINTENANCE.md +689 -0
  24. package/bundled/locales/zh-CN/README.md +707 -0
  25. package/bundled/locales/zh-CN/STANDARDS-MAPPING.md +177 -0
  26. package/bundled/locales/zh-CN/adoption/ADOPTION-GUIDE.md +392 -0
  27. package/bundled/locales/zh-CN/adoption/STATIC-DYNAMIC-GUIDE.md +302 -0
  28. package/bundled/locales/zh-CN/adoption/checklists/enterprise.md +332 -0
  29. package/bundled/locales/zh-CN/adoption/checklists/minimal.md +141 -0
  30. package/bundled/locales/zh-CN/adoption/checklists/recommended.md +272 -0
  31. package/bundled/locales/zh-CN/ai/MAINTENANCE.md +739 -0
  32. package/bundled/locales/zh-CN/ai/options/changelog/auto-generated.ai.yaml +76 -0
  33. package/bundled/locales/zh-CN/ai/options/changelog/keep-a-changelog.ai.yaml +99 -0
  34. package/bundled/locales/zh-CN/ai/options/code-review/automated-review.ai.yaml +120 -0
  35. package/bundled/locales/zh-CN/ai/options/code-review/pair-programming.ai.yaml +109 -0
  36. package/bundled/locales/zh-CN/ai/options/code-review/pr-review.ai.yaml +104 -0
  37. package/bundled/locales/zh-CN/ai/options/commit-message/bilingual.ai.yaml +105 -0
  38. package/bundled/locales/zh-CN/ai/options/commit-message/english.ai.yaml +79 -0
  39. package/bundled/locales/zh-CN/ai/options/commit-message/traditional-chinese.ai.yaml +100 -0
  40. package/bundled/locales/zh-CN/ai/options/documentation/api-docs.ai.yaml +140 -0
  41. package/bundled/locales/zh-CN/ai/options/documentation/markdown-docs.ai.yaml +89 -0
  42. package/bundled/locales/zh-CN/ai/options/documentation/wiki-style.ai.yaml +119 -0
  43. package/bundled/locales/zh-CN/ai/options/git-workflow/gitflow.ai.yaml +133 -0
  44. package/bundled/locales/zh-CN/ai/options/git-workflow/github-flow.ai.yaml +73 -0
  45. package/bundled/locales/zh-CN/ai/options/git-workflow/merge-commit.ai.yaml +88 -0
  46. package/bundled/locales/zh-CN/ai/options/git-workflow/rebase-ff.ai.yaml +113 -0
  47. package/bundled/locales/zh-CN/ai/options/git-workflow/squash-merge.ai.yaml +85 -0
  48. package/bundled/locales/zh-CN/ai/options/git-workflow/trunk-based.ai.yaml +117 -0
  49. package/bundled/locales/zh-CN/ai/options/project-structure/dotnet.ai.yaml +108 -0
  50. package/bundled/locales/zh-CN/ai/options/project-structure/go.ai.yaml +115 -0
  51. package/bundled/locales/zh-CN/ai/options/project-structure/java.ai.yaml +113 -0
  52. package/bundled/locales/zh-CN/ai/options/project-structure/kotlin.ai.yaml +123 -0
  53. package/bundled/locales/zh-CN/ai/options/project-structure/nodejs.ai.yaml +101 -0
  54. package/bundled/locales/zh-CN/ai/options/project-structure/php.ai.yaml +147 -0
  55. package/bundled/locales/zh-CN/ai/options/project-structure/python.ai.yaml +116 -0
  56. package/bundled/locales/zh-CN/ai/options/project-structure/ruby.ai.yaml +140 -0
  57. package/bundled/locales/zh-CN/ai/options/project-structure/rust.ai.yaml +117 -0
  58. package/bundled/locales/zh-CN/ai/options/project-structure/swift.ai.yaml +143 -0
  59. package/bundled/locales/zh-CN/ai/options/testing/contract-testing.ai.yaml +254 -0
  60. package/bundled/locales/zh-CN/ai/options/testing/e2e-testing.ai.yaml +116 -0
  61. package/bundled/locales/zh-CN/ai/options/testing/industry-pyramid.ai.yaml +144 -0
  62. package/bundled/locales/zh-CN/ai/options/testing/integration-testing.ai.yaml +90 -0
  63. package/bundled/locales/zh-CN/ai/options/testing/istqb-framework.ai.yaml +108 -0
  64. package/bundled/locales/zh-CN/ai/options/testing/performance-testing.ai.yaml +272 -0
  65. package/bundled/locales/zh-CN/ai/options/testing/security-testing.ai.yaml +160 -0
  66. package/bundled/locales/zh-CN/ai/options/testing/system-testing.ai.yaml +101 -0
  67. package/bundled/locales/zh-CN/ai/options/testing/unit-testing.ai.yaml +82 -0
  68. package/bundled/locales/zh-CN/ai/standards/anti-hallucination.ai.yaml +145 -0
  69. package/bundled/locales/zh-CN/ai/standards/changelog.ai.yaml +146 -0
  70. package/bundled/locales/zh-CN/ai/standards/checkin-standards.ai.yaml +170 -0
  71. package/bundled/locales/zh-CN/ai/standards/code-review.ai.yaml +148 -0
  72. package/bundled/locales/zh-CN/ai/standards/commit-message.ai.yaml +175 -0
  73. package/bundled/locales/zh-CN/ai/standards/documentation-structure.ai.yaml +124 -0
  74. package/bundled/locales/zh-CN/ai/standards/documentation-writing-standards.ai.yaml +190 -0
  75. package/bundled/locales/zh-CN/ai/standards/error-codes.ai.yaml +139 -0
  76. package/bundled/locales/zh-CN/ai/standards/git-workflow.ai.yaml +95 -0
  77. package/bundled/locales/zh-CN/ai/standards/logging.ai.yaml +128 -0
  78. package/bundled/locales/zh-CN/ai/standards/project-structure.ai.yaml +134 -0
  79. package/bundled/locales/zh-CN/ai/standards/spec-driven-development.ai.yaml +169 -0
  80. package/bundled/locales/zh-CN/ai/standards/test-completeness-dimensions.ai.yaml +220 -0
  81. package/bundled/locales/zh-CN/ai/standards/testing.ai.yaml +137 -0
  82. package/bundled/locales/zh-CN/ai/standards/versioning.ai.yaml +211 -0
  83. package/bundled/locales/zh-CN/core/ai-instruction-standards.md +213 -0
  84. package/bundled/locales/zh-CN/core/anti-hallucination.md +691 -0
  85. package/bundled/locales/zh-CN/core/changelog-standards.md +147 -0
  86. package/bundled/locales/zh-CN/core/checkin-standards.md +943 -0
  87. package/bundled/locales/zh-CN/core/code-review-guide.md +693 -0
  88. package/bundled/locales/zh-CN/core/commit-message-guide.md +129 -0
  89. package/bundled/locales/zh-CN/core/documentation-structure.md +173 -0
  90. package/bundled/locales/zh-CN/core/documentation-writing-standards.md +495 -0
  91. package/bundled/locales/zh-CN/core/error-code-standards.md +180 -0
  92. package/bundled/locales/zh-CN/core/git-workflow.md +193 -0
  93. package/bundled/locales/zh-CN/core/logging-standards.md +174 -0
  94. package/bundled/locales/zh-CN/core/project-structure.md +184 -0
  95. package/bundled/locales/zh-CN/core/refactoring-standards.md +642 -0
  96. package/bundled/locales/zh-CN/core/spec-driven-development.md +215 -0
  97. package/bundled/locales/zh-CN/core/test-completeness-dimensions.md +544 -0
  98. package/bundled/locales/zh-CN/core/test-driven-development.md +1002 -0
  99. package/bundled/locales/zh-CN/core/testing-standards.md +170 -0
  100. package/bundled/locales/zh-CN/core/versioning.md +177 -0
  101. package/bundled/locales/zh-CN/docs/AI-AGENT-ROADMAP.md +303 -0
  102. package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +990 -0
  103. package/bundled/locales/zh-CN/docs/OPERATION-WORKFLOW.md +1064 -0
  104. package/bundled/locales/zh-CN/docs/USAGE-MODES-COMPARISON.md +333 -0
  105. package/bundled/locales/zh-CN/docs/WINDOWS-GUIDE.md +215 -0
  106. package/bundled/locales/zh-CN/integrations/codex/AGENTS.md +115 -0
  107. package/bundled/locales/zh-CN/integrations/codex/README.md +67 -0
  108. package/bundled/locales/zh-CN/integrations/gemini-cli/GEMINI.md +102 -0
  109. package/bundled/locales/zh-CN/integrations/gemini-cli/README.md +140 -0
  110. package/bundled/locales/zh-CN/integrations/github-copilot/COPILOT-CHAT-REFERENCE.md +269 -0
  111. package/bundled/locales/zh-CN/integrations/github-copilot/README.md +167 -0
  112. package/bundled/locales/zh-CN/integrations/github-copilot/copilot-instructions.md +263 -0
  113. package/bundled/locales/zh-CN/integrations/github-copilot/skills-mapping.md +192 -0
  114. package/bundled/locales/zh-CN/integrations/google-antigravity/INSTRUCTIONS.md +61 -0
  115. package/bundled/locales/zh-CN/integrations/google-antigravity/README.md +84 -0
  116. package/bundled/locales/zh-CN/integrations/opencode/AGENTS.md +111 -0
  117. package/bundled/locales/zh-CN/integrations/opencode/README.md +176 -0
  118. package/bundled/locales/zh-CN/integrations/opencode/skills-mapping.md +396 -0
  119. package/bundled/locales/zh-CN/integrations/openspec/AGENTS.md +301 -0
  120. package/bundled/locales/zh-CN/integrations/openspec/README.md +43 -0
  121. package/bundled/locales/zh-CN/integrations/spec-kit/AGENTS.md +184 -0
  122. package/bundled/locales/zh-CN/integrations/spec-kit/README.md +43 -0
  123. package/bundled/locales/zh-CN/options/commit-message/bilingual.md +161 -0
  124. package/bundled/locales/zh-CN/options/commit-message/english.md +137 -0
  125. package/bundled/locales/zh-CN/options/commit-message/traditional-chinese.md +162 -0
  126. package/bundled/locales/zh-CN/options/git-workflow/gitflow.md +147 -0
  127. package/bundled/locales/zh-CN/options/git-workflow/github-flow.md +124 -0
  128. package/bundled/locales/zh-CN/options/git-workflow/merge-commit.md +124 -0
  129. package/bundled/locales/zh-CN/options/git-workflow/rebase-ff.md +160 -0
  130. package/bundled/locales/zh-CN/options/git-workflow/squash-merge.md +117 -0
  131. package/bundled/locales/zh-CN/options/git-workflow/trunk-based.md +125 -0
  132. package/bundled/locales/zh-CN/options/project-structure/dotnet.md +183 -0
  133. package/bundled/locales/zh-CN/options/project-structure/go.md +226 -0
  134. package/bundled/locales/zh-CN/options/project-structure/java.md +213 -0
  135. package/bundled/locales/zh-CN/options/project-structure/nodejs.md +185 -0
  136. package/bundled/locales/zh-CN/options/project-structure/python.md +229 -0
  137. package/bundled/locales/zh-CN/options/testing/e2e-testing.md +207 -0
  138. package/bundled/locales/zh-CN/options/testing/integration-testing.md +230 -0
  139. package/bundled/locales/zh-CN/options/testing/system-testing.md +183 -0
  140. package/bundled/locales/zh-CN/options/testing/unit-testing.md +165 -0
  141. package/bundled/locales/zh-CN/skills/INTEGRATION-GUIDE.md +218 -0
  142. package/bundled/locales/zh-CN/skills/README.md +134 -0
  143. package/bundled/locales/zh-CN/skills/_shared/README.md +68 -0
  144. package/bundled/locales/zh-CN/skills/claude-code/CONTRIBUTING.template.md +151 -0
  145. package/bundled/locales/zh-CN/skills/claude-code/README.md +174 -0
  146. package/bundled/locales/zh-CN/skills/claude-code/ai-collaboration-standards/SKILL.md +175 -0
  147. package/bundled/locales/zh-CN/skills/claude-code/ai-collaboration-standards/anti-hallucination.md +223 -0
  148. package/bundled/locales/zh-CN/skills/claude-code/ai-collaboration-standards/certainty-labels.md +132 -0
  149. package/bundled/locales/zh-CN/skills/claude-code/changelog-guide/SKILL.md +237 -0
  150. package/bundled/locales/zh-CN/skills/claude-code/checkin-assistant/SKILL.md +407 -0
  151. package/bundled/locales/zh-CN/skills/claude-code/code-review-assistant/SKILL.md +154 -0
  152. package/bundled/locales/zh-CN/skills/claude-code/code-review-assistant/checkin-checklist.md +257 -0
  153. package/bundled/locales/zh-CN/skills/claude-code/code-review-assistant/review-checklist.md +246 -0
  154. package/bundled/locales/zh-CN/skills/claude-code/commands/bdd.md +142 -0
  155. package/bundled/locales/zh-CN/skills/claude-code/commands/methodology.md +274 -0
  156. package/bundled/locales/zh-CN/skills/claude-code/commit-standards/SKILL.md +191 -0
  157. package/bundled/locales/zh-CN/skills/claude-code/commit-standards/conventional-commits.md +264 -0
  158. package/bundled/locales/zh-CN/skills/claude-code/commit-standards/language-options.md +172 -0
  159. package/bundled/locales/zh-CN/skills/claude-code/documentation-guide/SKILL.md +421 -0
  160. package/bundled/locales/zh-CN/skills/claude-code/documentation-guide/documentation-structure.md +357 -0
  161. package/bundled/locales/zh-CN/skills/claude-code/documentation-guide/readme-template.md +412 -0
  162. package/bundled/locales/zh-CN/skills/claude-code/error-code-guide/SKILL.md +269 -0
  163. package/bundled/locales/zh-CN/skills/claude-code/git-workflow-guide/SKILL.md +218 -0
  164. package/bundled/locales/zh-CN/skills/claude-code/git-workflow-guide/branch-naming.md +220 -0
  165. package/bundled/locales/zh-CN/skills/claude-code/git-workflow-guide/git-workflow.md +321 -0
  166. package/bundled/locales/zh-CN/skills/claude-code/logging-guide/SKILL.md +285 -0
  167. package/bundled/locales/zh-CN/skills/claude-code/methodology-system/SKILL.md +131 -0
  168. package/bundled/locales/zh-CN/skills/claude-code/methodology-system/create-methodology.md +350 -0
  169. package/bundled/locales/zh-CN/skills/claude-code/methodology-system/runtime.md +279 -0
  170. package/bundled/locales/zh-CN/skills/claude-code/project-structure-guide/SKILL.md +143 -0
  171. package/bundled/locales/zh-CN/skills/claude-code/project-structure-guide/language-patterns.md +271 -0
  172. package/bundled/locales/zh-CN/skills/claude-code/refactoring-assistant/SKILL.md +162 -0
  173. package/bundled/locales/zh-CN/skills/claude-code/release-standards/SKILL.md +191 -0
  174. package/bundled/locales/zh-CN/skills/claude-code/release-standards/changelog-format.md +247 -0
  175. package/bundled/locales/zh-CN/skills/claude-code/release-standards/release-workflow.md +345 -0
  176. package/bundled/locales/zh-CN/skills/claude-code/release-standards/semantic-versioning.md +250 -0
  177. package/bundled/locales/zh-CN/skills/claude-code/requirement-assistant/SKILL.md +227 -0
  178. package/bundled/locales/zh-CN/skills/claude-code/requirement-assistant/requirement-checklist.md +325 -0
  179. package/bundled/locales/zh-CN/skills/claude-code/requirement-assistant/requirement-writing.md +399 -0
  180. package/bundled/locales/zh-CN/skills/claude-code/spec-driven-dev/SKILL.md +243 -0
  181. package/bundled/locales/zh-CN/skills/claude-code/tdd-assistant/SKILL.md +332 -0
  182. package/bundled/locales/zh-CN/skills/claude-code/tdd-assistant/language-examples.md +639 -0
  183. package/bundled/locales/zh-CN/skills/claude-code/tdd-assistant/tdd-workflow.md +486 -0
  184. package/bundled/locales/zh-CN/skills/claude-code/test-coverage-assistant/SKILL.md +282 -0
  185. package/bundled/locales/zh-CN/skills/claude-code/testing-guide/SKILL.md +234 -0
  186. package/bundled/locales/zh-CN/skills/claude-code/testing-guide/testing-pyramid.md +448 -0
  187. package/bundled/locales/zh-CN/skills/cline/README.md +58 -0
  188. package/bundled/locales/zh-CN/skills/copilot/README.md +61 -0
  189. package/bundled/locales/zh-CN/skills/copilot/copilot-instructions.md +79 -0
  190. package/bundled/locales/zh-CN/skills/cursor/README.md +58 -0
  191. package/bundled/locales/zh-CN/skills/windsurf/README.md +59 -0
  192. package/bundled/locales/zh-TW/CHANGELOG.md +707 -0
  193. package/bundled/locales/zh-TW/CLAUDE.md +213 -0
  194. package/bundled/locales/zh-TW/MAINTENANCE.md +683 -0
  195. package/bundled/locales/zh-TW/README.md +687 -0
  196. package/bundled/locales/zh-TW/STANDARDS-MAPPING.md +177 -0
  197. package/bundled/locales/zh-TW/adoption/ADOPTION-GUIDE.md +392 -0
  198. package/bundled/locales/zh-TW/adoption/STATIC-DYNAMIC-GUIDE.md +299 -0
  199. package/bundled/locales/zh-TW/adoption/checklists/enterprise.md +332 -0
  200. package/bundled/locales/zh-TW/adoption/checklists/minimal.md +141 -0
  201. package/bundled/locales/zh-TW/adoption/checklists/recommended.md +272 -0
  202. package/bundled/locales/zh-TW/ai/MAINTENANCE.md +754 -0
  203. package/bundled/locales/zh-TW/ai/options/changelog/auto-generated.ai.yaml +76 -0
  204. package/bundled/locales/zh-TW/ai/options/changelog/keep-a-changelog.ai.yaml +99 -0
  205. package/bundled/locales/zh-TW/ai/options/code-review/automated-review.ai.yaml +120 -0
  206. package/bundled/locales/zh-TW/ai/options/code-review/pair-programming.ai.yaml +109 -0
  207. package/bundled/locales/zh-TW/ai/options/code-review/pr-review.ai.yaml +104 -0
  208. package/bundled/locales/zh-TW/ai/options/commit-message/bilingual.ai.yaml +105 -0
  209. package/bundled/locales/zh-TW/ai/options/commit-message/english.ai.yaml +79 -0
  210. package/bundled/locales/zh-TW/ai/options/commit-message/traditional-chinese.ai.yaml +100 -0
  211. package/bundled/locales/zh-TW/ai/options/documentation/api-docs.ai.yaml +140 -0
  212. package/bundled/locales/zh-TW/ai/options/documentation/markdown-docs.ai.yaml +89 -0
  213. package/bundled/locales/zh-TW/ai/options/documentation/wiki-style.ai.yaml +119 -0
  214. package/bundled/locales/zh-TW/ai/options/git-workflow/gitflow.ai.yaml +133 -0
  215. package/bundled/locales/zh-TW/ai/options/git-workflow/github-flow.ai.yaml +73 -0
  216. package/bundled/locales/zh-TW/ai/options/git-workflow/merge-commit.ai.yaml +88 -0
  217. package/bundled/locales/zh-TW/ai/options/git-workflow/rebase-ff.ai.yaml +113 -0
  218. package/bundled/locales/zh-TW/ai/options/git-workflow/squash-merge.ai.yaml +85 -0
  219. package/bundled/locales/zh-TW/ai/options/git-workflow/trunk-based.ai.yaml +117 -0
  220. package/bundled/locales/zh-TW/ai/options/project-structure/dotnet.ai.yaml +108 -0
  221. package/bundled/locales/zh-TW/ai/options/project-structure/go.ai.yaml +115 -0
  222. package/bundled/locales/zh-TW/ai/options/project-structure/java.ai.yaml +113 -0
  223. package/bundled/locales/zh-TW/ai/options/project-structure/kotlin.ai.yaml +123 -0
  224. package/bundled/locales/zh-TW/ai/options/project-structure/nodejs.ai.yaml +101 -0
  225. package/bundled/locales/zh-TW/ai/options/project-structure/php.ai.yaml +147 -0
  226. package/bundled/locales/zh-TW/ai/options/project-structure/python.ai.yaml +116 -0
  227. package/bundled/locales/zh-TW/ai/options/project-structure/ruby.ai.yaml +140 -0
  228. package/bundled/locales/zh-TW/ai/options/project-structure/rust.ai.yaml +117 -0
  229. package/bundled/locales/zh-TW/ai/options/project-structure/swift.ai.yaml +143 -0
  230. package/bundled/locales/zh-TW/ai/options/testing/contract-testing.ai.yaml +254 -0
  231. package/bundled/locales/zh-TW/ai/options/testing/e2e-testing.ai.yaml +116 -0
  232. package/bundled/locales/zh-TW/ai/options/testing/industry-pyramid.ai.yaml +144 -0
  233. package/bundled/locales/zh-TW/ai/options/testing/integration-testing.ai.yaml +90 -0
  234. package/bundled/locales/zh-TW/ai/options/testing/istqb-framework.ai.yaml +108 -0
  235. package/bundled/locales/zh-TW/ai/options/testing/performance-testing.ai.yaml +272 -0
  236. package/bundled/locales/zh-TW/ai/options/testing/security-testing.ai.yaml +160 -0
  237. package/bundled/locales/zh-TW/ai/options/testing/system-testing.ai.yaml +101 -0
  238. package/bundled/locales/zh-TW/ai/options/testing/unit-testing.ai.yaml +82 -0
  239. package/bundled/locales/zh-TW/ai/standards/anti-hallucination.ai.yaml +145 -0
  240. package/bundled/locales/zh-TW/ai/standards/changelog.ai.yaml +146 -0
  241. package/bundled/locales/zh-TW/ai/standards/checkin-standards.ai.yaml +170 -0
  242. package/bundled/locales/zh-TW/ai/standards/code-review.ai.yaml +148 -0
  243. package/bundled/locales/zh-TW/ai/standards/commit-message.ai.yaml +175 -0
  244. package/bundled/locales/zh-TW/ai/standards/documentation-structure.ai.yaml +124 -0
  245. package/bundled/locales/zh-TW/ai/standards/documentation-writing-standards.ai.yaml +190 -0
  246. package/bundled/locales/zh-TW/ai/standards/error-codes.ai.yaml +139 -0
  247. package/bundled/locales/zh-TW/ai/standards/git-workflow.ai.yaml +95 -0
  248. package/bundled/locales/zh-TW/ai/standards/logging.ai.yaml +128 -0
  249. package/bundled/locales/zh-TW/ai/standards/project-structure.ai.yaml +134 -0
  250. package/bundled/locales/zh-TW/ai/standards/spec-driven-development.ai.yaml +169 -0
  251. package/bundled/locales/zh-TW/ai/standards/test-completeness-dimensions.ai.yaml +220 -0
  252. package/bundled/locales/zh-TW/ai/standards/testing.ai.yaml +137 -0
  253. package/bundled/locales/zh-TW/ai/standards/versioning.ai.yaml +211 -0
  254. package/bundled/locales/zh-TW/core/ai-instruction-standards.md +213 -0
  255. package/bundled/locales/zh-TW/core/anti-hallucination.md +691 -0
  256. package/bundled/locales/zh-TW/core/changelog-standards.md +564 -0
  257. package/bundled/locales/zh-TW/core/checkin-standards.md +943 -0
  258. package/bundled/locales/zh-TW/core/code-review-checklist.md +693 -0
  259. package/bundled/locales/zh-TW/core/commit-message-guide.md +809 -0
  260. package/bundled/locales/zh-TW/core/documentation-structure.md +1125 -0
  261. package/bundled/locales/zh-TW/core/documentation-writing-standards.md +495 -0
  262. package/bundled/locales/zh-TW/core/error-code-standards.md +384 -0
  263. package/bundled/locales/zh-TW/core/git-workflow.md +860 -0
  264. package/bundled/locales/zh-TW/core/logging-standards.md +325 -0
  265. package/bundled/locales/zh-TW/core/project-structure.md +362 -0
  266. package/bundled/locales/zh-TW/core/refactoring-standards.md +642 -0
  267. package/bundled/locales/zh-TW/core/spec-driven-development.md +215 -0
  268. package/bundled/locales/zh-TW/core/test-completeness-dimensions.md +544 -0
  269. package/bundled/locales/zh-TW/core/test-driven-development.md +1004 -0
  270. package/bundled/locales/zh-TW/core/testing-standards.md +2158 -0
  271. package/bundled/locales/zh-TW/core/versioning.md +909 -0
  272. package/bundled/locales/zh-TW/docs/AI-AGENT-ROADMAP.md +303 -0
  273. package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +990 -0
  274. package/bundled/locales/zh-TW/docs/OPERATION-WORKFLOW.md +1064 -0
  275. package/bundled/locales/zh-TW/docs/USAGE-MODES-COMPARISON.md +333 -0
  276. package/bundled/locales/zh-TW/docs/WINDOWS-GUIDE.md +215 -0
  277. package/bundled/locales/zh-TW/integrations/codex/AGENTS.md +115 -0
  278. package/bundled/locales/zh-TW/integrations/codex/README.md +113 -0
  279. package/bundled/locales/zh-TW/integrations/gemini-cli/GEMINI.md +102 -0
  280. package/bundled/locales/zh-TW/integrations/gemini-cli/README.md +140 -0
  281. package/bundled/locales/zh-TW/integrations/github-copilot/COPILOT-CHAT-REFERENCE.md +269 -0
  282. package/bundled/locales/zh-TW/integrations/github-copilot/README.md +167 -0
  283. package/bundled/locales/zh-TW/integrations/github-copilot/copilot-instructions.md +263 -0
  284. package/bundled/locales/zh-TW/integrations/github-copilot/skills-mapping.md +192 -0
  285. package/bundled/locales/zh-TW/integrations/google-antigravity/INSTRUCTIONS.md +61 -0
  286. package/bundled/locales/zh-TW/integrations/google-antigravity/README.md +84 -0
  287. package/bundled/locales/zh-TW/integrations/opencode/AGENTS.md +111 -0
  288. package/bundled/locales/zh-TW/integrations/opencode/README.md +176 -0
  289. package/bundled/locales/zh-TW/integrations/opencode/skills-mapping.md +396 -0
  290. package/bundled/locales/zh-TW/integrations/openspec/AGENTS.md +301 -0
  291. package/bundled/locales/zh-TW/integrations/openspec/README.md +43 -0
  292. package/bundled/locales/zh-TW/integrations/spec-kit/AGENTS.md +184 -0
  293. package/bundled/locales/zh-TW/integrations/spec-kit/README.md +43 -0
  294. package/bundled/locales/zh-TW/options/commit-message/bilingual.md +161 -0
  295. package/bundled/locales/zh-TW/options/commit-message/english.md +137 -0
  296. package/bundled/locales/zh-TW/options/commit-message/traditional-chinese.md +162 -0
  297. package/bundled/locales/zh-TW/options/git-workflow/gitflow.md +147 -0
  298. package/bundled/locales/zh-TW/options/git-workflow/github-flow.md +124 -0
  299. package/bundled/locales/zh-TW/options/git-workflow/merge-commit.md +124 -0
  300. package/bundled/locales/zh-TW/options/git-workflow/rebase-ff.md +160 -0
  301. package/bundled/locales/zh-TW/options/git-workflow/squash-merge.md +117 -0
  302. package/bundled/locales/zh-TW/options/git-workflow/trunk-based.md +125 -0
  303. package/bundled/locales/zh-TW/options/project-structure/dotnet.md +183 -0
  304. package/bundled/locales/zh-TW/options/project-structure/go.md +226 -0
  305. package/bundled/locales/zh-TW/options/project-structure/java.md +213 -0
  306. package/bundled/locales/zh-TW/options/project-structure/nodejs.md +185 -0
  307. package/bundled/locales/zh-TW/options/project-structure/python.md +229 -0
  308. package/bundled/locales/zh-TW/options/testing/e2e-testing.md +207 -0
  309. package/bundled/locales/zh-TW/options/testing/integration-testing.md +230 -0
  310. package/bundled/locales/zh-TW/options/testing/system-testing.md +183 -0
  311. package/bundled/locales/zh-TW/options/testing/unit-testing.md +165 -0
  312. package/bundled/locales/zh-TW/skills/INTEGRATION-GUIDE.md +218 -0
  313. package/bundled/locales/zh-TW/skills/README.md +132 -0
  314. package/bundled/locales/zh-TW/skills/_shared/README.md +68 -0
  315. package/bundled/locales/zh-TW/skills/claude-code/CONTRIBUTING.template.md +151 -0
  316. package/bundled/locales/zh-TW/skills/claude-code/README.md +174 -0
  317. package/bundled/locales/zh-TW/skills/claude-code/ai-collaboration-standards/SKILL.md +175 -0
  318. package/bundled/locales/zh-TW/skills/claude-code/ai-collaboration-standards/anti-hallucination.md +223 -0
  319. package/bundled/locales/zh-TW/skills/claude-code/ai-collaboration-standards/certainty-labels.md +132 -0
  320. package/bundled/locales/zh-TW/skills/claude-code/changelog-guide/SKILL.md +237 -0
  321. package/bundled/locales/zh-TW/skills/claude-code/checkin-assistant/SKILL.md +407 -0
  322. package/bundled/locales/zh-TW/skills/claude-code/code-review-assistant/SKILL.md +154 -0
  323. package/bundled/locales/zh-TW/skills/claude-code/code-review-assistant/checkin-checklist.md +257 -0
  324. package/bundled/locales/zh-TW/skills/claude-code/code-review-assistant/review-checklist.md +246 -0
  325. package/bundled/locales/zh-TW/skills/claude-code/commands/bdd.md +142 -0
  326. package/bundled/locales/zh-TW/skills/claude-code/commands/methodology.md +274 -0
  327. package/bundled/locales/zh-TW/skills/claude-code/commit-standards/SKILL.md +191 -0
  328. package/bundled/locales/zh-TW/skills/claude-code/commit-standards/conventional-commits.md +264 -0
  329. package/bundled/locales/zh-TW/skills/claude-code/commit-standards/language-options.md +172 -0
  330. package/bundled/locales/zh-TW/skills/claude-code/documentation-guide/SKILL.md +421 -0
  331. package/bundled/locales/zh-TW/skills/claude-code/documentation-guide/documentation-structure.md +357 -0
  332. package/bundled/locales/zh-TW/skills/claude-code/documentation-guide/readme-template.md +412 -0
  333. package/bundled/locales/zh-TW/skills/claude-code/error-code-guide/SKILL.md +269 -0
  334. package/bundled/locales/zh-TW/skills/claude-code/git-workflow-guide/SKILL.md +218 -0
  335. package/bundled/locales/zh-TW/skills/claude-code/git-workflow-guide/branch-naming.md +220 -0
  336. package/bundled/locales/zh-TW/skills/claude-code/git-workflow-guide/git-workflow.md +321 -0
  337. package/bundled/locales/zh-TW/skills/claude-code/logging-guide/SKILL.md +285 -0
  338. package/bundled/locales/zh-TW/skills/claude-code/methodology-system/SKILL.md +131 -0
  339. package/bundled/locales/zh-TW/skills/claude-code/methodology-system/create-methodology.md +350 -0
  340. package/bundled/locales/zh-TW/skills/claude-code/methodology-system/runtime.md +279 -0
  341. package/bundled/locales/zh-TW/skills/claude-code/project-structure-guide/SKILL.md +143 -0
  342. package/bundled/locales/zh-TW/skills/claude-code/project-structure-guide/language-patterns.md +271 -0
  343. package/bundled/locales/zh-TW/skills/claude-code/refactoring-assistant/SKILL.md +162 -0
  344. package/bundled/locales/zh-TW/skills/claude-code/release-standards/SKILL.md +191 -0
  345. package/bundled/locales/zh-TW/skills/claude-code/release-standards/changelog-format.md +247 -0
  346. package/bundled/locales/zh-TW/skills/claude-code/release-standards/release-workflow.md +345 -0
  347. package/bundled/locales/zh-TW/skills/claude-code/release-standards/semantic-versioning.md +250 -0
  348. package/bundled/locales/zh-TW/skills/claude-code/requirement-assistant/SKILL.md +227 -0
  349. package/bundled/locales/zh-TW/skills/claude-code/requirement-assistant/requirement-checklist.md +325 -0
  350. package/bundled/locales/zh-TW/skills/claude-code/requirement-assistant/requirement-writing.md +399 -0
  351. package/bundled/locales/zh-TW/skills/claude-code/spec-driven-dev/SKILL.md +243 -0
  352. package/bundled/locales/zh-TW/skills/claude-code/tdd-assistant/SKILL.md +332 -0
  353. package/bundled/locales/zh-TW/skills/claude-code/tdd-assistant/language-examples.md +639 -0
  354. package/bundled/locales/zh-TW/skills/claude-code/tdd-assistant/tdd-workflow.md +486 -0
  355. package/bundled/locales/zh-TW/skills/claude-code/test-coverage-assistant/SKILL.md +282 -0
  356. package/bundled/locales/zh-TW/skills/claude-code/testing-guide/SKILL.md +234 -0
  357. package/bundled/locales/zh-TW/skills/claude-code/testing-guide/testing-pyramid.md +448 -0
  358. package/bundled/locales/zh-TW/skills/cline/README.md +58 -0
  359. package/bundled/locales/zh-TW/skills/copilot/README.md +61 -0
  360. package/bundled/locales/zh-TW/skills/copilot/copilot-instructions.md +79 -0
  361. package/bundled/locales/zh-TW/skills/cursor/README.md +58 -0
  362. package/bundled/locales/zh-TW/skills/windsurf/README.md +59 -0
  363. package/bundled/skills/claude-code/CONTRIBUTING.template.md +141 -0
  364. package/bundled/skills/claude-code/README.md +196 -0
  365. package/bundled/skills/claude-code/ai/standards/checkin.ai.yaml +21 -0
  366. package/bundled/skills/claude-code/ai/standards/commit.ai.yaml +20 -0
  367. package/bundled/skills/claude-code/ai/standards/refactoring.ai.yaml +34 -0
  368. package/bundled/skills/claude-code/ai/standards/testing.ai.yaml +41 -0
  369. package/bundled/skills/claude-code/ai-collaboration-standards/SKILL.md +175 -0
  370. package/bundled/skills/claude-code/ai-collaboration-standards/anti-hallucination.md +215 -0
  371. package/bundled/skills/claude-code/ai-collaboration-standards/certainty-labels.md +124 -0
  372. package/bundled/skills/claude-code/changelog-guide/SKILL.md +232 -0
  373. package/bundled/skills/claude-code/checkin-assistant/SKILL.md +402 -0
  374. package/bundled/skills/claude-code/code-review-assistant/SKILL.md +220 -0
  375. package/bundled/skills/claude-code/code-review-assistant/checkin-checklist.md +249 -0
  376. package/bundled/skills/claude-code/code-review-assistant/review-checklist.md +238 -0
  377. package/bundled/skills/claude-code/commands/README.md +78 -0
  378. package/bundled/skills/claude-code/commands/bdd.md +142 -0
  379. package/bundled/skills/claude-code/commands/changelog.md +57 -0
  380. package/bundled/skills/claude-code/commands/check.md +91 -0
  381. package/bundled/skills/claude-code/commands/commit.md +48 -0
  382. package/bundled/skills/claude-code/commands/config.md +97 -0
  383. package/bundled/skills/claude-code/commands/coverage.md +58 -0
  384. package/bundled/skills/claude-code/commands/docs.md +75 -0
  385. package/bundled/skills/claude-code/commands/init.md +88 -0
  386. package/bundled/skills/claude-code/commands/methodology.md +268 -0
  387. package/bundled/skills/claude-code/commands/release.md +50 -0
  388. package/bundled/skills/claude-code/commands/requirement.md +54 -0
  389. package/bundled/skills/claude-code/commands/review.md +50 -0
  390. package/bundled/skills/claude-code/commands/spec.md +69 -0
  391. package/bundled/skills/claude-code/commands/tdd.md +86 -0
  392. package/bundled/skills/claude-code/commands/update.md +122 -0
  393. package/bundled/skills/claude-code/commit-standards/SKILL.md +249 -0
  394. package/bundled/skills/claude-code/commit-standards/conventional-commits.md +256 -0
  395. package/bundled/skills/claude-code/commit-standards/language-options.md +164 -0
  396. package/bundled/skills/claude-code/documentation-guide/SKILL.md +416 -0
  397. package/bundled/skills/claude-code/documentation-guide/documentation-structure.md +349 -0
  398. package/bundled/skills/claude-code/documentation-guide/readme-template.md +404 -0
  399. package/bundled/skills/claude-code/error-code-guide/SKILL.md +264 -0
  400. package/bundled/skills/claude-code/git-workflow-guide/SKILL.md +226 -0
  401. package/bundled/skills/claude-code/git-workflow-guide/branch-naming.md +212 -0
  402. package/bundled/skills/claude-code/git-workflow-guide/git-workflow.md +313 -0
  403. package/bundled/skills/claude-code/logging-guide/SKILL.md +280 -0
  404. package/bundled/skills/claude-code/methodology-system/SKILL.md +215 -0
  405. package/bundled/skills/claude-code/methodology-system/create-methodology.md +450 -0
  406. package/bundled/skills/claude-code/methodology-system/runtime.md +271 -0
  407. package/bundled/skills/claude-code/project-structure-guide/SKILL.md +143 -0
  408. package/bundled/skills/claude-code/project-structure-guide/language-patterns.md +263 -0
  409. package/bundled/skills/claude-code/refactoring-assistant/SKILL.md +205 -0
  410. package/bundled/skills/claude-code/release-standards/SKILL.md +191 -0
  411. package/bundled/skills/claude-code/release-standards/changelog-format.md +239 -0
  412. package/bundled/skills/claude-code/release-standards/release-workflow.md +337 -0
  413. package/bundled/skills/claude-code/release-standards/semantic-versioning.md +242 -0
  414. package/bundled/skills/claude-code/requirement-assistant/SKILL.md +222 -0
  415. package/bundled/skills/claude-code/requirement-assistant/requirement-checklist.md +317 -0
  416. package/bundled/skills/claude-code/requirement-assistant/requirement-writing.md +391 -0
  417. package/bundled/skills/claude-code/spec-driven-dev/SKILL.md +238 -0
  418. package/bundled/skills/claude-code/tdd-assistant/SKILL.md +384 -0
  419. package/bundled/skills/claude-code/tdd-assistant/language-examples.md +1276 -0
  420. package/bundled/skills/claude-code/tdd-assistant/tdd-workflow.md +659 -0
  421. package/bundled/skills/claude-code/test-coverage-assistant/SKILL.md +277 -0
  422. package/bundled/skills/claude-code/testing-guide/SKILL.md +317 -0
  423. package/bundled/skills/claude-code/testing-guide/testing-pyramid.md +440 -0
  424. package/package.json +4 -2
  425. package/src/commands/check.js +38 -6
  426. package/src/commands/init.js +20 -6
  427. package/src/commands/list.js +7 -2
  428. package/src/commands/skills.js +0 -2
  429. package/src/commands/update.js +271 -0
  430. package/src/i18n/messages.js +161 -11
  431. package/src/utils/copier.js +63 -10
  432. package/src/utils/skills-installer.js +47 -11
  433. package/standards-registry.json +6 -3
@@ -0,0 +1,1002 @@
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
+ # 测试驱动开发 (TDD) 标准
10
+
11
+ **版本**: 1.1.0
12
+ **最后更新**: 2026-01-12
13
+ **适用范围**: 所有采用测试驱动开发的专案
14
+
15
+ > **语言**: [English](../../../core/test-driven-development.md) | 繁体中文
16
+
17
+ ---
18
+
19
+ ## 目的
20
+
21
+ 本标准定义了测试驱动开发 (TDD) 的原则、工作流程和最佳实践,确保测试能够驱动软体功能的设计与实作。
22
+
23
+ **主要优点**:
24
+ - 设计从测试中浮现,产生更具可测试性和模组化的程序码
25
+ - 对程序码正确性获得即时回馈
26
+ - 测试作为活文件
27
+ - 减少除错时间和缺陷率
28
+ - 对重构更有信心
29
+
30
+ ---
31
+
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 遵循一个简单但强大的迭代循环:
58
+
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
+ ```
89
+
90
+ ### 循环时间建议
91
+
92
+ | 阶段 | 建议时间 | 警示讯号 |
93
+ |------|---------|---------|
94
+ | 🔴 红 | 1-5 分钟 | 若超过 10 分钟,测试范围太大 |
95
+ | 🟢 绿 | 1-10 分钟 | 若超过 15 分钟,需要分解问题 |
96
+ | 🔵 重构 | 5-15 分钟 | 若跳过,技术债会累积 |
97
+
98
+ ### 口诀
99
+
100
+ > **红 → 绿 → 重构 → 重复**
101
+
102
+ 每次迭代都应该很小。如果你发现自己在任何阶段花费太长时间,测试可能太有野心了。
103
+
104
+ ---
105
+
106
+ ## TDD 原则
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
+ ```
249
+
250
+ ---
251
+
252
+ ## TDD vs BDD vs ATDD
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
+ ```
554
+
555
+ ### Given-When-Then 模式(BDD 风格)
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
+ 根据 Martin Fowler 的《Refactoring》(第二版),代码异味分为五大类别:
637
+
638
+ #### 1. 膨胀型(Bloaters)
639
+
640
+ 代码变得过大且难以处理。
641
+
642
+ | 异味 | 说明 | 重构方式 |
643
+ |------|------|---------|
644
+ | **Long Method(过长方法)** | 方法超过 20 行,做太多事 | Extract Method、Replace Temp with Query、Introduce Parameter Object |
645
+ | **Large Class(过大类)** | 类有太多职责 | Extract Class、Extract Subclass、Extract Interface |
646
+ | **Primitive Obsession(基本类型偏执)** | 过度使用基本类型而非小对象 | Replace Primitive with Object、Replace Type Code with Class、Introduce Parameter Object |
647
+ | **Long Parameter List(过长参数列表)** | 方法有太多参数(>3 个) | Introduce Parameter Object、Preserve Whole Object、Replace Parameter with Method Call |
648
+ | **Data Clumps(数据泥团)** | 相同的数据群组一起出现 | Extract Class、Introduce Parameter Object、Preserve Whole Object |
649
+
650
+ #### 2. 面向对象滥用者(OO Abusers)
651
+
652
+ 不完整或不正确的面向对象应用。
653
+
654
+ | 异味 | 说明 | 重构方式 |
655
+ |------|------|---------|
656
+ | **Switch Statements(Switch 语句)** | 复杂的 switch/if-else 链基于类型 | Replace Conditional with Polymorphism、Replace Type Code with Strategy、Replace Type Code with State |
657
+ | **Temporary Field(临时字段)** | 只在某些情况下有值的字段 | Extract Class、Introduce Null Object、Introduce Special Case |
658
+ | **Refused Bequest(被拒绝的遗产)** | 子类不使用继承的方法 | Push Down Method、Push Down Field、Replace Inheritance with Delegation |
659
+ | **Alternative Classes with Different Interfaces(接口不同的替代类)** | 做相同事情但有不同方法签名的类 | Rename Method、Move Method、Extract Superclass |
660
+ | **Parallel Inheritance Hierarchies(平行继承层次)** | 创建子类需要在另一个层次中创建另一个 | Move Method、Move Field |
661
+
662
+ #### 3. 变更阻碍者(Change Preventers)
663
+
664
+ 使变更比必要更困难的代码。
665
+
666
+ | 异味 | 说明 | 重构方式 |
667
+ |------|------|---------|
668
+ | **Divergent Change(发散式变更)** | 一个类因多种不同原因被修改 | Extract Class、Split Phase |
669
+ | **Shotgun Surgery(散弹枪手术)** | 一个变更需要修改多个类 | Move Method、Move Field、Inline Function、Inline Class |
670
+ | **Parallel Inheritance Hierarchies(平行继承层次)** | (见上方) | Move Method、Move Field |
671
+
672
+ #### 4. 可有可无者(Dispensables)
673
+
674
+ 可以移除的不必要代码。
675
+
676
+ | 异味 | 说明 | 重构方式 |
677
+ |------|------|---------|
678
+ | **Comments(注释)** | 隐藏糟糕代码的过多注释 | Extract Method、Rename Method、Introduce Assertion |
679
+ | **Duplicate Code(重复代码)** | 多处相同或相似的代码 | Extract Method、Pull Up Method、Extract Class、Slide Statements |
680
+ | **Dead Code(死代码)** | 未使用的代码(变量、方法、类) | Remove Dead Code |
681
+ | **Lazy Class(懒惰类)** | 做太少事而不值得存在的类 | Inline Class、Collapse Hierarchy |
682
+ | **Speculative Generality(推测式通用性)** | 「为将来使用」的未使用抽象 | Collapse Hierarchy、Inline Function、Inline Class、Remove Dead Code |
683
+ | **Data Class(数据类)** | 只有字段和 getter/setter 的类 | Move Method、Encapsulate Field、Encapsulate Collection |
684
+
685
+ #### 5. 耦合者(Couplers)
686
+
687
+ 类之间过度耦合的代码。
688
+
689
+ | 异味 | 说明 | 重构方式 |
690
+ |------|------|---------|
691
+ | **Feature Envy(功能嫉妒)** | 方法使用另一个类的数据多于自己的 | Move Method、Extract Method |
692
+ | **Inappropriate Intimacy(不当亲密)** | 类过于紧密耦合,访问彼此的私有部分 | Move Method、Move Field、Hide Delegate、Replace Delegation with Inheritance |
693
+ | **Message Chains(消息链)** | `a.getB().getC().getD().getValue()` | Hide Delegate、Extract Method、Move Method |
694
+ | **Middle Man(中间人)** | 类只是委托给另一个类 | Remove Middle Man、Inline Function、Replace Superclass with Delegate |
695
+
696
+ ### 代码异味检测检查清单
697
+
698
+ 快速检查清单以识别常见异味:
699
+
700
+ ```
701
+ 方法/函数层级:
702
+ □ 方法 > 20 行? → Extract Method
703
+ □ > 3 个参数? → Introduce Parameter Object
704
+ □ 深度嵌套(> 3 层)? → Extract Method、Replace Nested Conditional with Guard Clauses
705
+ □ 多个 return 语句? → 考虑重构
706
+
707
+ 类层级:
708
+ □ 类 > 200 行? → Extract Class
709
+ □ > 10 个方法? → 考虑拆分职责
710
+ □ 上帝类(什么都做)? → Extract Class
711
+ □ 数据类(只有字段)? → 把行为移进来
712
+
713
+ 代码模式:
714
+ □ 基于类型的 Switch? → Replace with Polymorphism
715
+ □ 复制粘贴代码? → Extract Method/Class
716
+ □ 未使用的代码? → 删除它
717
+ □ 魔法数字? → Replace with Named Constant
718
+ ```
719
+
720
+ ### 安全重构检查清单
721
+
722
+ ```
723
+ 重构前:
724
+ □ 所有测试都通过(绿色)
725
+ □ 有足够的测试覆盖
726
+ □ 你理解代码在做什么
727
+
728
+ 重构中:
729
+ □ 一次只做「一个」小变更
730
+ □ 「每次」变更后执行测试
731
+ □ 如果测试失败,立即恢复
732
+ □ 重构时不要新增功能
733
+
734
+ 重构后:
735
+ □ 所有测试仍然通过
736
+ □ 代码更干净/简单
737
+ □ 没有新增功能
738
+ ```
739
+
740
+ ### 常见重构技术
741
+
742
+ | 技术 | 使用时机 | 示例 |
743
+ |------|---------|------|
744
+ | **Extract Method** | 过长方法、重复代码 | 提取 10 行到 `calculateDiscount()` |
745
+ | **Rename** | 不清楚的名称 | `calc()` → `calculateOrderTotal()` |
746
+ | **Inline** | 过度抽象 | 移除不必要的包装函数 |
747
+ | **Extract Variable** | 复杂表达式 | `const isEligible = age >= 18 && hasLicense` |
748
+ | **Replace Conditional with Polymorphism** | 复杂的 switch/if 链 | 使用策略模式 |
749
+ | **Introduce Parameter Object** | 太多参数 | `(x, y, width, height)` → `Rectangle rect` |
750
+
751
+ ---
752
+
753
+ ## TDD 中的测试替身
754
+
755
+ ### 测试替身类型
756
+
757
+ | 类型 | 目的 | 使用时机 |
758
+ |------|------|---------|
759
+ | **Dummy** | 填充参数列表 | 必要参数但测试中未使用 |
760
+ | **Stub** | 回传预定义的值 | 模拟特定场景 |
761
+ | **Spy** | 记录互动 | 验证方法是否被呼叫 |
762
+ | **Mock** | 验证互动 + 回传值 | 测试行为和协作 |
763
+ | **Fake** | 简化的实作 | 记忆体内资料库 |
764
+
765
+ ### 依测试层级的测试替身使用
766
+
767
+ | 层级 | 建议的替身 |
768
+ |------|-----------|
769
+ | **单元测试** | 所有外部依赖使用 Mock、Stub |
770
+ | **集成测试** | DB 使用 Fake,外部 API 使用 Stub |
771
+ | **系统测试** | 真实元件,只有外部服务使用 Fake |
772
+ | **E2E 测试** | 全部使用真实 |
773
+
774
+ ### 范例:使用 Mock 和 Stub
775
+
776
+ ```typescript
777
+ // Stub 范例 - 预定义的回传值
778
+ const paymentGateway = {
779
+ processPayment: jest.fn().mockResolvedValue({ success: true, transactionId: 'TXN123' })
780
+ };
781
+
782
+ // Mock 范例 - 验证互动
783
+ const emailService = {
784
+ sendConfirmation: jest.fn()
785
+ };
786
+
787
+ test('should send confirmation email after successful payment', async () => {
788
+ const order = new OrderService(paymentGateway, emailService);
789
+
790
+ await order.checkout({ amount: 100, email: 'user@example.com' });
791
+
792
+ // 验证 mock 是否使用正确的参数被呼叫
793
+ expect(emailService.sendConfirmation).toHaveBeenCalledWith(
794
+ 'user@example.com',
795
+ expect.objectContaining({ transactionId: 'TXN123' })
796
+ );
797
+ });
798
+ ```
799
+
800
+ ### 避免过度 Mock
801
+
802
+ ```
803
+ ❌ 过度 mock(测试实作细节):
804
+ - Mock 私有方法
805
+ - Mock 每一个依赖
806
+ - 验证每一个内部方法呼叫
807
+
808
+ ✅ 适当的 mock:
809
+ - Mock 外部服务(API、资料库)
810
+ - Mock 慢速操作(档案 I/O、网路)
811
+ - Mock 非确定性操作(时间、随机)
812
+ ```
813
+
814
+ ---
815
+
816
+ ## 反模式与修复
817
+
818
+ ### 程序码层级反模式
819
+
820
+ | 反模式 | 说明 | 影响 | 修复方式 |
821
+ |--------|------|------|---------|
822
+ | **测试实作细节** | 测试私有方法或内部状态 | 脆弱的测试,重构会破坏测试 | 只测试公开行为 |
823
+ | **过度 Mock** | Mock 所有东西,失去真实性 | 虚假的信心,bug 进入生产环境 | 平衡 mock 和真实元件 |
824
+ | **测试相依性** | 测试依赖执行顺序 | 随机失败,难以隔离 | 每个测试设置自己的状态 |
825
+ | **魔术数字/字串** | 没有意义的硬编码值 | 可读性差,维护噩梦 | 使用命名常数、建构器 |
826
+ | **缺少断言** | 测试没有适当的断言 | 假阳性 | 每个测试需要明确的断言 |
827
+ | **不稳定测试** | 有时通过,有时失败 | 对测试套件信任度降低 | 消除时间/顺序依赖 |
828
+ | **过大的 Arrange 区块** | 每个测试都有复杂设置 | 难以理解、维护 | 提取设置到建构器/fixtures |
829
+ | **测试中的条件逻辑** | 测试程序码中的 if/else | 一个测试中有多个测试 | 分割成独立的测试 |
830
+ | **测试程序码重复** | 许多测试中相同的设置 | 维护负担 | 提取共享设置 |
831
+ | **过于特定的断言** | 断言每一个栏位 | 脆弱的测试 | 只断言相关栏位 |
832
+ | **忽略测试失败** | 跳过或注解掉失败的测试 | 隐藏的 bug | 修复或移除失败的测试 |
833
+ | **测试第三方程序码** | 测试程序库/框架行为 | 浪费努力 | 信任第三方,测试你的程序码 |
834
+ | **一个巨大的测试** | 单一测试涵盖所有 | 难以诊断失败 | 分割成聚焦的测试 |
835
+ | **没有测试名称** | `test1`、`test2` | 无法理解 | 使用描述性名称 |
836
+ | **捕获所有例外** | 测试中的 `catch (Exception e)` | 隐藏的失败 | 捕获特定例外 |
837
+
838
+ ### 流程层级反模式
839
+
840
+ | 反模式 | 说明 | 影响 | 修复方式 |
841
+ |--------|------|------|---------|
842
+ | **跳过红色阶段** | 在测试之前写程序码 | 失去 TDD 设计优点 | 纪律:始终先写失败的测试 |
843
+ | **跳过重构阶段** | 从不清理 | 技术债累积 | 安排重构时间 |
844
+ | **开发后测试 (TAD)** | 程序码完成后才写测试 | 不是 TDD,错过设计回馈 | 真正的 TDD:测试优先 |
845
+ | **一次写所有测试** | 同时写所有测试 | 不堪负荷,覆盖率差 | 一次一个测试 |
846
+ | **100% 覆盖率迷思** | 追求覆盖率指标 | 无意义的测试 | 专注于行为覆盖 |
847
+ | **不审查测试** | PR 中不审查测试 | 测试品质差 | 在程序码审查中包含测试 |
848
+ | **延迟执行测试** | 不常执行测试 | 回馈延迟 | 持续执行测试 |
849
+ | **忽略慢速测试** | 让测试套件变慢 | 开发者跳过测试 | 优化或并行化 |
850
+ | **TDD 狂热** | 到处强制使用 TDD | 团队挫败 | 务实地应用 TDD |
851
+ | **不维护测试** | 让测试腐败 | 假阳性/假阴性 | 将测试视为生产程序码 |
852
+
853
+ ### 诊断与修复步骤
854
+
855
+ ```
856
+ ┌─────────────────────────────────────────────────────────────────┐
857
+ │ 反模式诊断工作流程 │
858
+ ├─────────────────────────────────────────────────────────────────┤
859
+ │ │
860
+ │ 症状:重构时测试经常失败 │
861
+ │ ├─ 可能原因:测试实作细节 │
862
+ │ └─ 修复:审查测试,确保只测试行为 │
863
+ │ │
864
+ │ 症状:测试通过但 bug 进入生产环境 │
865
+ │ ├─ 可能原因:过度 mock,缺少边界情况 │
866
+ │ └─ 修复:新增集成测试,审查覆盖差距 │
867
+ │ │
868
+ │ 症状:测试随机失败 │
869
+ │ ├─ 可能原因:测试相依性,时间问题 │
870
+ │ └─ 修复:隔离测试,mock 时间相关操作 │
871
+ │ │
872
+ │ 症状:测试套件执行时间太长 │
873
+ │ ├─ 可能原因:集成测试太多,慢速 I/O │
874
+ │ └─ 修复:增加单元测试比例,并行化 │
875
+ │ │
876
+ │ 症状:团队回避写测试 │
877
+ │ ├─ 可能原因:测试太复杂,工具不佳 │
878
+ │ └─ 修复:简化测试设置,改善测试工具 │
879
+ │ │
880
+ └─────────────────────────────────────────────────────────────────┘
881
+ ```
882
+
883
+ ---
884
+
885
+ ## 语言/框架实践
886
+
887
+ 详细的语言特定 TDD 范例,请参阅 TDD Assistant skill:
888
+ - [语言范例](../skills/claude-code/tdd-assistant/language-examples.md)
889
+
890
+ ### 依语言快速参考
891
+
892
+ | 语言 | 测试框架 | Mock 程序库 | BDD 工具 |
893
+ |------|---------|------------|---------|
894
+ | **JavaScript/TypeScript** | Jest, Vitest | jest.mock, vitest.mock | Cucumber.js |
895
+ | **Python** | pytest, unittest | unittest.mock, pytest-mock | Behave |
896
+ | **C#** | xUnit, NUnit, MSTest | Moq, NSubstitute | SpecFlow |
897
+ | **Java** | JUnit 5, TestNG | Mockito, EasyMock | Cucumber-JVM |
898
+ | **Go** | testing | testify/mock | godog |
899
+ | **Ruby** | RSpec, minitest | rspec-mocks | Cucumber |
900
+
901
+ ### 框架选择指南
902
+
903
+ | 考量 | 建议 |
904
+ |------|------|
905
+ | **新专案** | 使用 IDE 支援最好的框架 |
906
+ | **团队经验** | 使用团队最熟悉的 |
907
+ | **现有程序码库** | 匹配现有测试框架 |
908
+ | **需要 BDD** | 选择有 BDD 集成的框架 |
909
+ | **速度关键** | 考虑并行执行支援 |
910
+
911
+ ---
912
+
913
+ ## 度量与评估
914
+
915
+ ### TDD 成熟度模型
916
+
917
+ | 层级 | 名称 | 特征 |
918
+ |------|------|------|
919
+ | **Level 0** | 无 TDD | 程序码之后写测试(如果有的话) |
920
+ | **Level 1** | 测试优先 | 有时在程序码之前写测试 |
921
+ | **Level 2** | TDD 实践者 | 一致的红-绿-重构循环 |
922
+ | **Level 3** | TDD 专家 | 有效的测试替身,干净的测试 |
923
+ | **Level 4** | TDD 大师 | TDD 驱动设计,指导他人 |
924
+
925
+ ### 关键指标
926
+
927
+ | 指标 | 目标 | 警示阈值 |
928
+ |------|------|---------|
929
+ | **程序码覆盖率** | > 80% | < 60% |
930
+ | **测试对程序码比** | 1:1 到 2:1 | < 0.5:1 |
931
+ | **测试执行时间** | < 30 秒(单元) | > 2 分钟 |
932
+ | **不稳定测试率** | 0% | > 1% |
933
+ | **测试维护成本** | < 15% 开发时间 | > 30% |
934
+ | **缺陷逃逸率** | 下降中 | 上升中 |
935
+
936
+ ### 评估检查清单
937
+
938
+ ```
939
+ 团队 TDD 评估:
940
+
941
+ □ 在生产程序码之前写测试
942
+ □ 遵循红-绿-重构循环
943
+ □ 测试名称清楚描述行为
944
+ □ 测试是独立且可重复的
945
+ □ 测试套件执行快速(< 2 分钟)
946
+ □ 没有不稳定的测试
947
+ □ 足够的覆盖率(> 80%)
948
+ □ 程序码审查中审查测试
949
+ □ 定期进行重构
950
+ □ CI/CD 自动执行测试
951
+ ```
952
+
953
+ ---
954
+
955
+ ## 相关标准
956
+
957
+ - [测试标准](testing-standards.md) - 核心测试标准(UT/IT/ST/E2E)(或使用 `/testing-guide` 技能)
958
+ - [测试完整性维度](test-completeness-dimensions.md) - 7 维度框架
959
+ - [规格驱动开发](spec-driven-development.md) - SDD 工作流程
960
+ - [程序码入库标准](checkin-standards.md) - 入库要求
961
+ - [程序码审查检查清单](code-review-checklist.md) - 审查指南
962
+
963
+ ---
964
+
965
+ ## 参考资料
966
+
967
+ ### 书籍
968
+
969
+ - Kent Beck - "Test Driven Development: By Example" (2002)
970
+ - Robert C. Martin - "Clean Code" 第 9 章:单元测试 (2008)
971
+ - Michael Feathers - "Working Effectively with Legacy Code" (2004)
972
+ - Steve Freeman & Nat Pryce - "Growing Object-Oriented Software, Guided by Tests" (2009)
973
+
974
+ ### 标准
975
+
976
+ - [IEEE 29119 - 软体测试标准](https://www.iso.org/standard/81291.html)
977
+ - [SWEBOK v4.0 - 第 5 章:软体建构](https://www.computer.org/education/bodies-of-knowledge/software-engineering)
978
+ - [ISTQB 认证测试员基础级](https://www.istqb.org/)
979
+
980
+ ### 线上资源
981
+
982
+ - [TDD by Example - Martin Fowler](https://martinfowler.com/bliki/TestDrivenDevelopment.html)
983
+ - [The Three Rules of TDD - Uncle Bob](http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd)
984
+ - [Test Pyramid - Martin Fowler](https://martinfowler.com/bliki/TestPyramid.html)
985
+ - [Approval Tests](https://approvaltests.com/)
986
+
987
+ ---
988
+
989
+ ## 版本历史
990
+
991
+ | 版本 | 日期 | 变更 |
992
+ |------|------|------|
993
+ | 1.1.0 | 2026-01-12 | 新增:完整代码异味目录(22+ 种异味分 5 类,基于 Martin Fowler《Refactoring》第二版)、代码异味检测检查清单 |
994
+ | 1.0.0 | 2026-01-07 | 初始 TDD 标准定义 |
995
+
996
+ ---
997
+
998
+ ## 授权
999
+
1000
+ 本标准依据 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 授权释出。
1001
+
1002
+ **来源**: [universal-dev-standards](https://github.com/AsiaOstrich/universal-dev-standards)