TDD/BDD 特别适用于 Rails 应用程序
使用 TDD/BDD 方法开发应用程序时应该达到多细粒度?特别是对于 Rails 应用程序。
您会单独测试每个字段,然后进行正确的迁移以使其通过吗?那么每个领域都会有自己的迁移吗?您实际上会测试什么来确保该领域是他们的?
我真的很想弄清楚从哪里开始以及如何细化。我一开始就愣住了,因为我不知道如何测试每一个小东西。
我见过的大多数示例都使用验证作为示例。我知道在此之前编写了更多代码,但我只是不知道如何测试最基本的内容,例如“应该有名字字段”。
非常感谢任何帮助。
谢谢!
How granular should one get when using TDD/BDD methods for developing an application? In particular with regards to a Rails application.
Would you test for every single field individually and then right the migration that will make it pass? So every field would have it's own migration? What would you actually test against to make sure the field was their?
I'm really trying to get my head wrapped around where to start and how granular to get. I go to get started and just freeze because I don't know how to test every little thing.
Most of the examples I've seen use validation as an example. I know there is a lot more code written before that and I just don't know how to test the most basic of things like "should have a first name field".
Any help is much appreciated.
THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会钻那么远。事实上,我通常不会测试我的迁移,并且(一般来说)当然不值得您花时间来测试 getter 和 setter。坚持进行能够让您了解系统并表达代码的重要功能需求的测试。
至于从哪里开始:选择一个您知道如何测试的需求 - 一个没有外部依赖性的需求,一个路径绝对清晰的需求。编写测试来描述所需的行为,实现它,并重构代码以消除您在实现过程中可能添加的任何丑陋之处。对列表中的一些功能完成此操作后,您可能会发现一些较模糊的功能正在成为焦点,因为您已经创建了它们所需的构建块/依赖项。
一本比AWDR或The Rails Way更详细地介绍测试实践的好书是The RSpec Book,其测试版以电子形式提供。
I wouldn't drill that far down. In fact, I don't usually test my migrations, and it's certainly not worth your time (in general) to test getters and setters. Stick to tests that teach you about the system, and express non-trivial functional requirements of the code.
As far as where to start: Pick a requirement that you know how to test - one without outside dependencies, one where the path is absolutely clear. Write the test(s) to describe the desired behavior, implement it, and refactor the code to remove any ugliness you may have added during the implementation. After you've done this for a few features on the list, you'll probably find that some of the fuzzier features are coming into focus because you've made the building blocks/dependencies that they need.
A good book that goes into more detail on testing practices than AWDR or The Rails Way is The RSpec Book, a beta of which is available in electronic form.
您是否使用任何 TDD/BDD 工具,例如 Cucumber?
他们有一些关于 在 Rails 中使用 Cucumber 的好信息。
基本上编写您的功能,然后编写一个脚手架以使该功能通过测试。当您想向模型添加另一个字段时,首先更新功能,让它失败,然后编写迁移并更新视图以使测试通过。
Are you using any tools for TDD/BDD such as Cucumber?
They have some good info about using Cucumber with Rails.
Basically write your feature and then a scaffold to make that feature pass it's tests. When you want to add another field to your model, first update the feature, let it fail, then write a migration and update your view to make the tests pass.