tdd

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TDD

TDD

Loop

循环

  1. Red — write one failing check for the next behaviour slice.
  2. Green — make the smallest implementation pass.
  3. Refactor — simplify while the check stays green.
  4. Repeat until the contract is covered.
  1. Red — 为下一个行为切片编写一个失败的检查。
  2. Green — 用最小实现使检查通过。
  3. Refactor — 在检查保持通过的同时简化实现。
  4. 重复上述过程,直到覆盖完整契约。

Output

输出

Name every phase:
Red
,
Green
,
Refactor
,
Repeat
. Finish with:
Passing check
,
Normal command
,
Untestable
(none or remaining edge).
Completion: every requested behavior has a passing check, the check ran in the repo's normal command, and any untestable edge is reported.
逐一列出每个阶段:
Red
、
Green
、
Refactor
、
Repeat
。最后以以下内容结束:
Passing check
、
Normal command
、
Untestable
(无或剩余边缘情况)。
完成标准:每个要求的行为都有通过的检查,检查通过仓库的常规命令运行,并且已报告任何无法测试的边缘情况。

Test choice

测试选择

Prefer the highest-level test that proves the behaviour without brittle setup. HTTP paths: request/response tests. Service/repository: integration tests when practical. Go: table-driven with
testify/require
if project uses it. Keep mocks at boundaries. Do not mock what you can run cheaply. One
assert
-style self-check suffices for tiny cases.
优先选择能够证明行为且不需要脆弱测试设置的最高层级测试。对于 HTTP 路径,使用请求/响应测试。对于 Service/Repository,在可行时使用集成测试。对于 Go,如果项目使用
testify/require
,则采用 table-driven 测试。将 mock 保留在系统边界。不要 mock 那些可以低成本实际运行的部分。对于极小场景,一个
assert
风格的自检即可满足要求。