CSC/ECE 517 Fall 2012/ch1b 1w69 mv: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
 
(97 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Introduction to Behavior-Driven Design and User Stories ==
<big>''' Introduction to Behavior-Driven Design and User Stories'''</big><br>
 
Behaviour Driven Design( abbreviated '''BDD''') is a [http://en.wikipedia.org/wiki/Software_development_methodology software development methodology] which involves incorporating [http://en.wikipedia.org/wiki/Stakeholder stakeholder’s] point of view in the development of the software. The software is implemented by taking into consideration its behavior as described by its stakeholders.


Behaviour Driven Design is a software development methodology which involves incorporating stakeholder’s point of view in the development of the software. The software is implemented by taking into consideration its behaviour as described by its stakeholders.


=== Need for BDD ===
=== Need for BDD ===
BDD comes under agile development. Agile development came into picture to overcome the reasons for software project failure.Some of the reasons for software project failure are:
BDD was developed by [http://dannorth.net/introducing-bdd Dan North ] .BDD comes under [http://en.wikipedia.org/wiki/Agile_software_development agile development]. Agile development came into picture to overcome the reasons for software project failure.Some of the reasons for software project failure are:<ref name="video">http://www.youtube.com/watch?v=q_A5kAMygOI<br></ref>


* Lack of understanding of user requirements.
* Lack of understanding of user requirements.
Line 13: Line 14:
* Miscommunication or lack of communication between stakeholders.
* Miscommunication or lack of communication between stakeholders.


Agile development involves stakeholder participation throughout the lifetown of the product.
Agile development involves stakeholder participation throughout the lifetime of the product.
BDD helps achieve this objective of agile development.User stories are written in BDD to describe the feature that is to be implemented.User stories can then be used to write tests to check  the behaviour desired by the stakeholder.TDD approach can then be used to implement the system.
BDD helps achieve this objective of agile development.[http://en.wikipedia.org/wiki/User_story User stories] are written in BDD to describe the feature that is to be implemented.User stories can then be used to write tests to check  the behaviour desired by the stakeholder.[http://en.wikipedia.org/wiki/Test-driven_development Test Driven Development] approach can then be used to implement the system.


=== Understanding BDD ===
=== Understanding BDD ===  


In order to reduce miscommunication and increase stakeholder participation, BDD asks questions about behaviour of application before and during development. To communicate effectively with people, it is necessary to use plain english language so that regular non- technical people can express and understand their requirements clearly.This is achieved by using user stories.The feature identified from the interaction with the customer is represented in 1-3 sentences in everyday language in a user story. In most of the cases user stories are written on “ 3x5 “ index cards. The advantage of using “3x5“ cards is that all the stakeholders can give their opinions without being intimidated.This involves all the customers in the brainstorming session. The compact size of the card allows stakeholders to prioritize the features and change them as required during development.Release dates can also be associated with the cards.
In order to reduce miscommunication and increase stakeholder participation, BDD asks questions about behaviour of application before and during development. To communicate effectively with people, it is necessary to use plain english language so that non- technical people can express and understand their requirements clearly.This is achieved by using user stories.The feature identified from the interaction with the customer is represented in 1-3 sentences in everyday language in a user story. In most of the cases user stories are written on “ 3x5 “ [http://en.wikipedia.org/wiki/Index_card index cards]. The advantage of using “3x5“ cards is that all the stakeholders can give their opinions without being intimidated.This involves all the customers in the [http://en.wikipedia.org/wiki/Brainstorming brainstorming] session. The compact size of the card allows stakeholders to prioritize the features and change them as required during development.Release dates can also be associated with the cards.<ref name="video" />


===== Format =====
===== Format =====
The generally accepted format for user stories is as follows:
The generally accepted format for user stories is as follows:<ref name="video" /><ref name="web">http://www.ryangreenhall.com/articles/bdd-by-example.html<br></ref>
  '''As a''' [role]
  '''As a''' [role]
  '''So that''' [goal]
  '''So that''' [goal]
  '''I want to''' [task]
  '''I want to''' [task]
[[File:userstory.png|200 px|thumb|right|User Story for movie upload feature <ref name="video" />]]
Consider a video sharing website where users can upload, stream or download movies.One of the features of this site is that user can upload a movie. The user story for this feature is shown in the image on the right.


Consider a video sharing website where users can upload, stream or download movies.One of the features of this site is that user can upload a movie.
The user story for this feature is shown in fig ()
After identifying user stories we have to describe scenario.Scenario uses a sequence of steps that describe how the user expects the system to behave.
After identifying user stories we have to describe scenario.Scenario uses a sequence of steps that describe how the user expects the system to behave.


The format for describing a scenario is as follows:
The format for describing a scenario is as follows:<ref name="video" /><ref name="web" />
   '''Given'''[situation]
   '''Given'''[situation]
  ''' When''' [action]
  ''' When''' [action]
   '''Then''' [expected result]
   '''Then''' [expected result]


For the movie uploading user story described above, the scenario is as follows:
For the movie uploading user story described above, the scenario is as follows:<ref name="video" /><ref name="web" />


  '''Given'''[A movie file]
  '''Given'''[A movie file]
Line 44: Line 45:


The behaviour may be described differently by different users.
The behaviour may be described differently by different users.
Consider a library system  where once a student rents a book, the system recommends a list of books that the student is likely to rent in the future.
Consider a library system  where once a student rents a book, the system recommends a list of books that the student is likely to rent in the future. Different users of the system will have different perspective about the same feature.Consider the following example.


Different users of the system will have different perspective about the same feature.Consider the following example.
A student may write the following user story to describe the recommendation feature.
 
A student may write the following user story to describe the recommendation feature.
  '''As a''' student
  '''As a''' student
  '''So that''' I can rent the books in advance
  '''So that''' I can rent the books in advance
  '''I want to''' see the list of books that users usually rent after reading a particular book
  '''I want to''' see the list of books that users usually rent after reading a particular book


A librarian may write the following user story to describe the recommendation feature.
A librarian may write the following user story to describe the recommendation feature.
  '''As a''' Librarian
  '''As a''' Librarian
  '''So that''' I can maintain an inventory of all the books for which there is demand
  '''So that''' I can maintain an inventory of all the books for which there is demand
  '''I want to''' see the list of books that users usually rent after reading a particular book.
  '''I want to''' see the list of books that users usually rent after reading a particular book.


====Backlog====
The implementation of the entire system will consist of multiple user stories.Backlog is a collection of user stories that are pending. This backlog can be used to prioritize the features to be implemented.
The implementation of the entire system will consist of multiple user stories.Backlog is a collection of user stories that are pending. This backlog can be used to prioritize the features to be implemented.


=== Frameworks for BDD ===
=== Frameworks for BDD ===


JBehave and RBehave are the two popular frameworks that support BDD.  Consider the following example of playing a guitar. Tabs describe on which strings a player should place his finger on. This example illustrates the steps in implementing a programme using BDD approach. This programme will produce a rendition in a sound format for each of the input tab.
[http://jbehave.org/ JBehave] and [http://dannorth.net/2007/06/17/introducing-rbehave/ RBehave] are the two popular [http://en.wikipedia.org/wiki/Software_framework frameworks] that support BDD.  Consider the movie sharing website described above where users can upload, stream or download movies.


The first step in the BDD approach is to write a story for the feature to be implemented.
The '''first step''' in the BDD approach is to write a story for the feature to be implemented.


  Story: Play Tabs
'''Story:''' Upload Movie
'''As a''' movie fan
'''I would like''' to add a movie to Rotten Potatoes Database
'''So that''' I can share a movie with other fans


  '''As a''' music fan
The '''second step''' is the develop the scenario for the story to be implemented.
  '''I would like''' to convert guitar tabs to music
'''Scenario:''' MovieSharing
  '''So that''' I can hear what they sound like
'''Given''' A movie file
'''When''' the user uploads the file
'''Then''' the movie gets added to the RottenPotatoes database and appears in the list of movies.


The second step is the develop the scenario for the story to be implemented.
  '''Scenario:''' My My Hey Hey
  '''Given tab'''
  e|---------------------------------
  B|---------------------------------
  G|---------------------------------
  D|----------0--0-------------------
  A|-0--2--3----------2--0-----0--0--
  E|------------------------3--------
  '''When''' the guitar plays
  '''Then''' the following notes will be played
  A0 A2 A3 D0 D0 A2 A0 E3 A0 A0


The My My Hey Hey scenario can be used to check if the functionality has been implemented correctly.
The MovieSharing scenario can be used to check if the functionality has been implemented correctly.


The third step is to map stories to java
The '''third step''' is to map stories to java
 
* '''Creating the Scenario'''
==== Creating the Scenario:====


To create an executable scenario we have to import  org.jbehave.scenario.Scenario and a create a class to describe the scenario.
To create an executable scenario we have to import  org.jbehave.scenario.Scenario and a create a class to describe the scenario. (All the examples to explain BDD have been written in the JBehave Framework) <ref name="web" />


 
  package com.uploadmovie;
  package com.tabplayer;
  import org.jbehave.scenario.Scenario;
  import org.jbehave.scenario.Scenario;
  public class HeyHeyMyMy extends Scenario {
  public class MovieSharing extends Scenario {
       @SuppressWarnings("unchecked")
       @SuppressWarnings("unchecked")
     public HeyHeyMyMy() {
     public MovieSharing() {
           super();
           super();
     }
     }
Line 105: Line 96:
The above code will not produce any output since till now no steps are defined.
The above code will not produce any output since till now no steps are defined.


In the given example the HeyHeyMyMy will extend the Scenario class.
In the given example the MovieSharing class will extend the Scenario class.
 
* '''Defining Scenario Steps'''
    Defining Scenario Steps
 
To create the scenario steps extend org.jbehave.scenario.steps and define methods for each step in the scenario.
 
package com.tabplayer.steps;
 
import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;
import org.jbehave.scenario.steps.Steps;


public class PlayTabSteps extends Steps {
To create the scenario steps extend org.jbehave.scenario.steps and define methods for each step in the scenario.<ref name="web" />


   @Given("tab $asciiTab")
package com.uploadmovie.steps;
   public void tab(String asciiTab) {
import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;
import org.jbehave.scenario.steps.Steps;
public class UploadMovieSteps extends Steps {
   @Given("movie $moviefilename")
   public void movie(String moviefilename) {
   }
   }
 
   @When("the the user uploads the file")
   @When("the guitar plays")
   public void movieUploads() {
   public void guitarPlays() {
   }
   }
 
   @Then("the movie gets added to the Rotten Potatoes database and appears in the list of movies")
   @Then("the following notes will be played $notes")
   public void themoviewillbedisplayed(String notes) {
   public void theFollowingNotesWillBePlayed(String notes) {
   }
   }
}
}


The Given, When and the Then annotations are mapped to the methods that will be called when the scenario is executed. The parameters are depicted using the $ sign. For example $asciiTab.
The Given, When and the Then [http://en.wikipedia.org/wiki/Java_annotation annotations] are mapped to the methods that will be called when the scenario is executed. The parameters are depicted using the $ sign. In the above scenario $moviename is a parameter.
* '''Passing Scenario Instance to the constructor of org.jbeahave.scenario.Scenario'''  <ref name="web" />


    Passing Scenario Instance to the constructor of org.jbeahave.scenario.Scenario.
package com.uploadmovie;
import org.jbehave.scenario.Scenario;
public class MovieSharing extends Scenario {
      @SuppressWarnings("unchecked")
    public MovieSharing() {
          super(new UploadMovieSteps());
    }
}


package com.tabplayer;
Here the instance of  the UploadMovieSteps class will be passed to the the constructor of org.jbeahave.scenario.Scenario.


import org.jbehave.scenario.Scenario;
If the method for the steps in the scenario are implemented correctly it should give the following output:


public class HeyHeyMyMy extends Scenario {
'''Given'''[A movie file]
 
'''When''' the user uploads the file
      @SuppressWarnings("unchecked")
  '''Then''' the movie gets added to the RottenPotatoes database and appears in the list of movies.
    public HeyHeyMyMy() {
          super(new PlayTabSteps());
    }
}
Here the instance of the PlayTabSteps class will be passed to the the constructor of org.jbeahave.scenario.Scenario.


If the method for the steps in the scenario are implemented correctly it should give the following output:
===Advantages of BDD and User Stories===


  Given tab
* Behaviour Driven Design focuses on customer involvement.Therefore the end product is likely to be according to the expectation of the customer.
  e|--------------------------------------
* User stories can be used to determine [http://www.boost.co.nz/blog/agile/acceptance-criteria/ acceptance criteria] and evaluate the success of the project.
  B|--------------------------------------
* User Stories are written in plain english. Therefore customers and end users can understand them easily.
  G|--------------------------------------
* The compact “3x5” cards facilitate maximum participation. They also help to prioritize the features to be implemented and find the backlog.
  D|----------0--0------------------------
* User stories can be used to write tests before coding which can save the trouble of debugging later. <ref name="notes"> https://docs.google.com/file/d/0B-WZbzkEKZrlYTI1OWZjNmItMWM0Mi00Y2IxLWEwYmQtOGFiN2RlYjBjMDRi/edit </ref>
  A|-0--2--3----------2--0-----0--0-------
  E|------------------------3-------------
  When the guitar plays
  Then the following notes will be played
  A0 A2 A3 D0 D0 A2 A0 E3 A0 A0
 


Advantages of BDD and User Stories
===Disadvantages of BDD and User Stories===


    Behaviour Driven Design focuses on customer involvement.Therefore the end product is likely to be according to the expectation of the customer.
* It is difficult to maintain continuous contact with the stakeholders.
    User stories can be used to determine acceptance criteria and evaluate the success of the project.
* Too much focus on the customers may lead to bad software architecture that is difficult to maintain. <ref name="notes" />
    User Stories are written in plain english. Therefore customers and end users can understand them easily.
    The compact “3x5” cards facilitate maximum participation. They also help to prioritize the features to be implemented and find the backlog.
    User stories can be used to write tests before coding which can save the trouble of debugging later.


==References==


Disadvantages of BDD and User Stories
<references />


    It is difficult to maintain continuous contact with the stakeholders.
==See also==
    It may lead to bad software architecture.(I dnt knw hw)
#[http://behaviour-driven.org/ Behaviour Driven Design]
#[http://en.wikipedia.org/wiki/Agile_software_development/ Agile Software Development]
#[http://dannorth.net/2007/06/17/introducing-rbehave/ RBehave]
#[http://www.ibm.com/developerworks/java/library/j-eaed2/index.html/ Test Driven Development]
#[http://blogs.collab.net/agile/2007/06/21/user-story-examples-and-counterexamples/ User Stories Examples]

Latest revision as of 20:08, 7 October 2012

Introduction to Behavior-Driven Design and User Stories

Behaviour Driven Design( abbreviated BDD) is a software development methodology which involves incorporating stakeholder’s point of view in the development of the software. The software is implemented by taking into consideration its behavior as described by its stakeholders.


Need for BDD

BDD was developed by Dan North .BDD comes under agile development. Agile development came into picture to overcome the reasons for software project failure.Some of the reasons for software project failure are:<ref name="video">http://www.youtube.com/watch?v=q_A5kAMygOI
</ref>

  • Lack of understanding of user requirements.
  • Changing requirements
  • Pressure to meet the project deadline.
  • Budget and time constraints
  • Difficulty in software development and management
  • Miscommunication or lack of communication between stakeholders.

Agile development involves stakeholder participation throughout the lifetime of the product. BDD helps achieve this objective of agile development.User stories are written in BDD to describe the feature that is to be implemented.User stories can then be used to write tests to check the behaviour desired by the stakeholder.Test Driven Development approach can then be used to implement the system.

Understanding BDD

In order to reduce miscommunication and increase stakeholder participation, BDD asks questions about behaviour of application before and during development. To communicate effectively with people, it is necessary to use plain english language so that non- technical people can express and understand their requirements clearly.This is achieved by using user stories.The feature identified from the interaction with the customer is represented in 1-3 sentences in everyday language in a user story. In most of the cases user stories are written on “ 3x5 “ index cards. The advantage of using “3x5“ cards is that all the stakeholders can give their opinions without being intimidated.This involves all the customers in the brainstorming session. The compact size of the card allows stakeholders to prioritize the features and change them as required during development.Release dates can also be associated with the cards.<ref name="video" />

Format

The generally accepted format for user stories is as follows:<ref name="video" /><ref name="web">http://www.ryangreenhall.com/articles/bdd-by-example.html
</ref>

As a [role]
So that [goal]
I want to [task]
User Story for movie upload feature <ref name="video" />

Consider a video sharing website where users can upload, stream or download movies.One of the features of this site is that user can upload a movie. The user story for this feature is shown in the image on the right.

After identifying user stories we have to describe scenario.Scenario uses a sequence of steps that describe how the user expects the system to behave.

The format for describing a scenario is as follows:<ref name="video" /><ref name="web" />

 Given[situation]
 When [action]
 Then [expected result]

For the movie uploading user story described above, the scenario is as follows:<ref name="video" /><ref name="web" />

Given[A movie file]
When the user uploads the file
Then the movie gets added to the RottenPotatoes database and appears in the list of movies.

Different User perception for the same requirement

The behaviour may be described differently by different users. Consider a library system where once a student rents a book, the system recommends a list of books that the student is likely to rent in the future. Different users of the system will have different perspective about the same feature.Consider the following example.

A student may write the following user story to describe the recommendation feature.

As a student
So that I can rent the books in advance
I want to see the list of books that users usually rent after reading a particular book

A librarian may write the following user story to describe the recommendation feature.

As a Librarian
So that I can maintain an inventory of all the books for which there is demand
I want to see the list of books that users usually rent after reading a particular book.

Backlog

The implementation of the entire system will consist of multiple user stories.Backlog is a collection of user stories that are pending. This backlog can be used to prioritize the features to be implemented.

Frameworks for BDD

JBehave and RBehave are the two popular frameworks that support BDD. Consider the movie sharing website described above where users can upload, stream or download movies.

The first step in the BDD approach is to write a story for the feature to be implemented.

Story: Upload Movie
As a movie fan
I would like to add a movie to Rotten Potatoes Database
So that I can share a movie with other fans

The second step is the develop the scenario for the story to be implemented.

Scenario: MovieSharing
Given A movie file
When the user uploads the file
Then the movie gets added to the RottenPotatoes database and appears in the list of movies.


The MovieSharing scenario can be used to check if the functionality has been implemented correctly.

The third step is to map stories to java

  • Creating the Scenario

To create an executable scenario we have to import org.jbehave.scenario.Scenario and a create a class to describe the scenario. (All the examples to explain BDD have been written in the JBehave Framework) <ref name="web" />

package com.uploadmovie;
import org.jbehave.scenario.Scenario;
public class MovieSharing extends Scenario {
      @SuppressWarnings("unchecked")
   public MovieSharing() {
          super();
   }
}

The above code will not produce any output since till now no steps are defined.

In the given example the MovieSharing class will extend the Scenario class.

  • Defining Scenario Steps

To create the scenario steps extend org.jbehave.scenario.steps and define methods for each step in the scenario.<ref name="web" />

package com.uploadmovie.steps;
import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;
import org.jbehave.scenario.steps.Steps;
public class UploadMovieSteps extends Steps {
  @Given("movie $moviefilename")
  public void movie(String moviefilename) {
  }
  @When("the the user uploads the file")
  public void movieUploads() {
  }
  @Then("the movie gets added to the Rotten Potatoes database and appears in the list of movies")
  public void themoviewillbedisplayed(String notes) {
  }
}

The Given, When and the Then annotations are mapped to the methods that will be called when the scenario is executed. The parameters are depicted using the $ sign. In the above scenario $moviename is a parameter.

  • Passing Scenario Instance to the constructor of org.jbeahave.scenario.Scenario <ref name="web" />
package com.uploadmovie;
import org.jbehave.scenario.Scenario;
public class MovieSharing extends Scenario {
      @SuppressWarnings("unchecked")
   public MovieSharing() {
          super(new UploadMovieSteps());
   }
}

Here the instance of the UploadMovieSteps class will be passed to the the constructor of org.jbeahave.scenario.Scenario.

If the method for the steps in the scenario are implemented correctly it should give the following output:

Given[A movie file]
When the user uploads the file
Then the movie gets added to the RottenPotatoes database and appears in the list of movies.

Advantages of BDD and User Stories

  • Behaviour Driven Design focuses on customer involvement.Therefore the end product is likely to be according to the expectation of the customer.
  • User stories can be used to determine acceptance criteria and evaluate the success of the project.
  • User Stories are written in plain english. Therefore customers and end users can understand them easily.
  • The compact “3x5” cards facilitate maximum participation. They also help to prioritize the features to be implemented and find the backlog.
  • User stories can be used to write tests before coding which can save the trouble of debugging later. <ref name="notes"> https://docs.google.com/file/d/0B-WZbzkEKZrlYTI1OWZjNmItMWM0Mi00Y2IxLWEwYmQtOGFiN2RlYjBjMDRi/edit </ref>

Disadvantages of BDD and User Stories

  • It is difficult to maintain continuous contact with the stakeholders.
  • Too much focus on the customers may lead to bad software architecture that is difficult to maintain. <ref name="notes" />

References

<references />

See also

  1. Behaviour Driven Design
  2. Agile Software Development
  3. RBehave
  4. Test Driven Development
  5. User Stories Examples