test-driven-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test-Driven Development

测试驱动开发

The Cycle

开发流程

Red

红(Red)

Write a test that describes the behavior you want. Run it. It should fail.
编写描述预期实现行为的测试用例,运行测试,此时测试应当失败。

Green

绿(Green)

Write the minimum code to make the test pass.
编写最少的代码让测试通过即可。

Refactor

重构(Refactor)

Make the code good. Tests must still pass.
优化代码质量,此过程中必须保证所有测试仍然通过。

Test Quality

测试质量

A good test:
  • Tests behavior, not implementation
  • Has one clear assertion
  • Has a descriptive name
  • Is independent
  • Is fast
一个优质的测试需要具备以下特性:
  • 测试行为,而非实现逻辑
  • 仅包含一个明确的断言
  • 命名具备描述性
  • 相互独立
  • 运行速度快