BDD: How does Baby steps work?
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 con开发者_StackOverflow中文版fused. I want to learn about the baby steps and I don't want to break it...
Thank you.
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:
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 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
int convertToDays(int monthCount,int daysCount)
And go by this steps. You firstly describe behavior of your code, coding goes after it. The next steps will be something like those:
- Fill the method to work correctly with int values
- Make it work with string input values.
- Add validation of data typed in
- Make user notification if input is not valid
- Do some refactoring
I hope it will help you. Thanks.
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.
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
精彩评论