且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当它们是对象依赖时,如何在编写源代码之前编写测试代码?

更新时间:2022-12-24 12:30:47

遵循严格的 TDD 工作流程,例如 TDD 的 3 条法则 绝对会打消你的犹豫.

Following a strict TDD workflow such as the 3 Laws of TDD would definitely put an end to your hesitations.

有了它,你就不能拥有诸如在设计和分析之后我已经实现了 MaterialCosntructor ......"之类的事情,因为你应该

With it you can't have such things as "After design and analysis i've implemented MaterialCosntructor ..." since you are supposed to

只编写足以通过测试的生产代码

Write only enough production code to pass a test

这基本上意味着:只需返回 "Yellow" 作为您的第一个实现.

Which basically means : just return "Yellow" as your first implementation.

然后您将添加更多测试(绿色、红色材料)并逐步设计您的类来处理这些额外的情况.

Then you would add more tests (green, red material) and incrementally design your class to handle these additional cases.