必须先用 TDD 编写测试吗?

发布于 2024-11-30 22:36:35 字数 298 浏览 3 评论 0原文

今天早上我和一位同事谈论了 TDD。在他看来,要真正做到TDD,测试必须先于代码编写。我认为,只要您的测试驱动您的代码并根据您正在进行 TDD 的测试的反馈做出决策(例如:注入依赖项、单一责任等...)。所以我认为测试优先和测试驱动之间应该有所区别。

我了解 TDD 规则,我读过书籍、博客和敏捷论坛。到目前为止,这里的每个人都已经给了我 TDD 的书本定义。

我之所以联系这个小组,是因为我们知道“解决方案不在教科书中”。另外,我需要知道我不是唯一一个认为这是合理的疯狂的人:)

是否必须先编写测试才能进行 TDD?你的意见是什么?

This morning I had a conversation with a co-worker about TDD. In his opinion to truly do TDD, the tests have to be written before the code. I argued that as long as your tests are driving your code and your making decisions (e.g.: injecting dependencies, Single responsibility etc...) based on the feedback from the tests that you're doing TDD. So I argued that there should be a distinction between Test First and Test Driven.

I understand the TDD rules, I've read the books, blogs and agile forums. So far everyone that's chimed in around here has given me the book text definition of TDD.

The reason why I'm reaching out to this group is because we know "the solution is not in the text book". Plus I need to know that I'm not the only crazy person who thinks this is reasonable :)

Do test have to be written first in order to do TDD? What is your opinion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

つ可否回来 2024-12-07 22:36:35

我认为重要的是这是一个迭代过程,迭代次数非常小。因此,如果您的第一步是创建一个文件并创建一个简单的类,其中一个方法被删除,然后编写一个调用该方法并失败的测试,那么我认为您首先创建哪个文件并不重要。您必须决定您要创建的东西看起来足以编写一个调用它的测试,谁在乎您保存文件的顺序?但如果迭代次数比这个大得多,那么您可能没有采用 TDD。将整个类预先编写为一次大迭代肯定不算作 TDD。

I think the important thing is that it's an iterative process where the iterations are very small. So if your first step is to create a file and make a bare-bones class with one method stubbed out, then write a test that calls that method and fails, then I think that it doesn't matter much which file you created first. You have to decide what the thing you're creating is going to look like enough to write a test that calls it, who cares what order you save the files in? But if the iterations get much larger than that then you're probably not doing TDD. Writing the whole class upfront as one big iteration would definitely not count as TDD.

转身泪倾城 2024-12-07 22:36:35

在纯 TDD 中,首先编写测试。如果团队有必要的纪律,我个人认为只要测试驱动开发就可以了。在测试涵盖所有功能之前,什么都不会“完成”。

in pure TDD, the tests are written first. If the team has the necessary discipline, I personally think its OK as long as tests drive the development. Nothing is 'done' until there are tests covering all the functionality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文