BDD:婴儿学步是如何运作的?
我正在尝试了解 BDD,并且我已经阅读了有关婴儿学步的内容。它们如何工作?我正在想办法。
例如,使用以下功能:
Feature: Months and days to days
In order to see months and days as days
As a date conversion fan
I need a webpage where users can enter days and
months and convert them to days.
Scenario: Convert 12 months and 0 days to days
Given “12” months And “0” days
When I click on convert button
Then I should get: 360
我应该创建代码以在步骤方法中进行正确的转换,然后重构代码并将它们放入类中,还是应该从类开始?
看起来很简单,但我很困惑。我想了解婴儿学步,但我不想打破它......
谢谢。
I'm trying to learn about BDD and I've read about baby steps. How do they work? I'm trying to figure it out.
For example, using the following feature:
Feature: Months and days to days
In order to see months and days as days
As a date conversion fan
I need a webpage where users can enter days and
months and convert them to days.
Scenario: Convert 12 months and 0 days to days
Given “12” months And “0” days
When I click on convert button
Then I should get: 360
Should I create a code to make the conversion right in the steps methods and then refactor the code and put them in classes or should I start with classes?
It's looks simple but I'm confused. I want to learn about the baby steps and I don't want to break it...
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,婴儿步骤意味着您只需一步一步地进行微小的改变。它类似于 TDD:编写新测试,编写代码,确保它不起作用,使其正常工作,编写新测试......等等
让我们看看你的例子:
我假设,您要做的第一件事是创建类名称,如“转换器”。第一步完成了。下一个小步骤是创建方法
并执行此步骤。您首先描述代码的行为,然后进行编码。
接下来的步骤将类似于以下步骤:
我希望它会对您有所帮助。谢谢。
As far as i can see, baby steps mean that you have to perform only small changes step by step. It is similar to TDD : write new test, write code, make sure that it does not works, make it work fine, write new test... etc
Lets look like onto your example:
I assume, that first thing you gotta do is create class name like a "Convertor". The first step done. The next small step is to create method
And go by this steps. You firstly describe behavior of your code, coding goes after it.
The next steps will be something like those:
I hope it will help you. Thanks.
你的问题很难理解,但作者可能会一步一步地从一个非常基本的场景开始,逐步发展到一个更复杂的场景。对于您描述的故事,最基本的示例可能是输入 0 个月和 0 天,并验证结果是否为 0 天。从那里,您可以从仅输入天或仅输入月份,最终到包含月份和日期的示例。
Your question is quite difficult to understand, but by baby steps the author probably means beginning with a very basic scenario and working up to a more complex one. For the story you describe, the most basic example could be entering 0 months and 0 days, and verifying that the result is 0 days. From there you could go from inputting only days or only months, and eventually to an example containing both months and days.
您还没有透露您正在使用什么平台,或者您是否有任何代码。红宝石?铁轨?爪哇? C#? Python?
婴儿步骤意味着以非常小的步骤前进,这并不奇怪,并且每次都重新运行测试。 “婴儿步骤”最初被设想应用于单元测试级别的内部红绿重构循环。 BDD 已经出现,并在验收测试级别添加了外部循环。 BDD风格是“由外向内”发展。
还有另一个经常组合使用的短语,类似于“让编译器指导您的步骤”。
假设您没有代码,并且您正在使用 Cucumber 和 RSpec - 描述在其他平台上不会有太大变化 - 当您在 Cucumber 中运行故事时,它会告诉您有未实现的步骤,甚至为您提供有关如何执行的基本建议实施您的给定时间和时间。
所以,宝贝脚步。采取其中之一,让我们说“给定”,并使用建议的实现。您在 Ruby 中创建一些步骤代码,其模式与该行匹配,然后调用什么……现在什么也不调用。在此代码中,它可能只是将参数转换为整数(稍后您可能会构建构造函数,但现在只做可能有效的最简单的事情)。
当您再次运行 Cucumber 时,它会抱怨缺少两个步骤,但有关您已填写的步骤的消息已更改。
现在填写下一步。当您再次运行 Cucumber 时,只有最后一步失败了。但你必须在第二步中添加更多内容。等等
看看这个教程,它会给你一些想法。
http://www.slideshare.net/josephwilk/outsidein-development -with-cucumber-and-rspec
You haven't said anything about what platform you are working on, or whether you have any code yet. Ruby? Rails? Java? C#? Python?
Baby steps means moving in very small steps, unsurprisingly, and re-running your tests each time. The "Baby steps" was originally conceived to apply to the inner red-green-refactor loop, at the unit test level. BDD has come along and added an external loop as well, at the acceptance test level. The BDD style is to develop "outside-in".
There is another phrase often used in combination, which goes something like "Let the compiler guide your steps".
Assuming you have no code, and you are using say Cucumber and RSpec - the description will not change much on other platforms - when you run your story in cucumber it will tell you you have unimplemented steps, and even give you basic suggestions as to how to implement your Given When and Then.
So, Baby Steps. Take one of those, let's say "Given", and use the suggested implementation. You create some step-code in Ruby, which pattern matches the line, and then calls what.. nothing for now. In this code it might simply convert the parameters to integers (later on you might build constructors, but for now just do the simplest thing that could possibly work).
When you run cucumber again, it complains about the two missing steps, but the message about the step you have filled in has changed.
Now fill in the next step. When you run cucumber again, only the last step is failing. But you have to add some more content to your second step. etc
Check out this tutorial, it gives you some idea.
http://www.slideshare.net/josephwilk/outsidein-development-with-cucumber-and-rspec