CSC/ECE 517 Fall 2014/ch1a 25 rs: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 12: Line 12:


==Concepts==
==Concepts==
===Three Core Principles===
===Three Core Principles of BDD===


<ol start="1">
<ol start="1">
Line 49: Line 49:
</pre>
</pre>


==Five Step Overview==
 


==Integrating with Eclipse==
==Integrating with Eclipse==
Line 88: Line 88:
.....
.....
..X..
..X..
</pre>
This exhibits the simplicity of the language involved.  Though it is a simple example, it is immediately readable and understandable even by those inexperienced in programming.
<pre>
Specification: Stack
When a new stack is created
Then it is empty
When an element is added to the stack
Then that element is at the top of the stack
When a stack has N elements
And element E is on top of the stack
Then a pop operation returns E
And the new size of the stack is N-1
</pre>
Similarly, this tests a very simple data structure that can be quickly understood by those not well versed in the exact underworkings of how a stack functions; they only need to know the most basic outline of a stack in order to find this Story completely readable.
And finally, a more specific stack testing implementation:
<pre>
Narrative:
In order to develop an application that requires a stack efficiently
As a development team
I would like to use an interface and implementation in Java directly
Scenario:  Basic functionality of a Stack
Given an empty stack
When the string Java is added
And the string C++ is added
And the last element is removed again
Then the resulting element should be Java
Scenario:  Stack search
Given an empty stack
When the string Java is added
And the string C++ is added
And the string PHP is added
And the element Java is searched for
Then the position returned should be 3
</pre>
</pre>


== References ==
== References ==
<span id="1foot">[[#1body|1.]]</span> http://jbehave.org/ <br>
<span id="1foot">[[#1body|1.]]</span> http://jbehave.org/ <br>
<span id="2foot">[[#1body|1.]]</span> http://en.wikipedia.org/wiki/Behavior-driven_development <br>
<span id="2foot">[[#1body|2.]]</span> http://en.wikipedia.org/wiki/Behavior-driven_development <br>
<span id="3foot">[[#1body|1.]]</span> http://www.ryangreenhall.com/articles/bdd-by-example.html <br>
<span id="3foot">[[#1body|3.]]</span> http://www.ryangreenhall.com/articles/bdd-by-example.html <br>
<span id="4foot">[[#1body|1.]]</span> http://behaviour-driven.org/ <br>
<span id="4foot">[[#1body|4.]]</span> http://behaviour-driven.org/ <br>
<span id="5foot">[[#1body|5.]]</span> https://blog.codecentric.de/en/2011/03/automated-acceptance-testing-using-jbehave/ <br>

Latest revision as of 00:26, 8 October 2014

JBehave

Behavior Driven Development

Overview

Behavior driven design (BDD) exists as an extension to Test Driven Development(TDD). Overall, BDD can be thought of as a specialized form of TDD that utilizes specialized tools (such as JBehave) to accomplish similar tasks with more emphasis on the accessibility of the program tests as opposed to the rigid, structured format of conventional acceptance tests.

Comparison to Test Driven Development

The language used for test cases immediately distinguishes BDD from TDD. Also, in BDD, the test cases emcompass both the specification for the program as well as the actual test case.

Background

JBehave is a Java-based framework that aims to function as a fully fledged development paradigm, utilizing communication and automation while using behavior based language in its descriptors. JBehave is the first ever created Behavior Driven Design platform, completed by Dan North.

Concepts

Three Core Principles of BDD

  1. Business and Technology should refer to the same system in the same way - ItsAllBehaviour
  2. Any system should have an identified, verifiable value to the business - WheresTheBusinessValue
  3. Up-front analysis, design and planning all have a diminishing return - EnoughIsEnough

Stories

A story is fundamentally defined as an "automatically executable increment of business functionality." We can think of this as a single component of functionality. Stories are further comprised of scenarios, which are defined as concrete examples of the behavior of the system. In other words, a specific instance of an implementation of a story. Scenarios are further broken down into steps, which are single statements that detail (step by step, if you will) exactly how a scenario will play out.

Keywords

BDD relies on the use of a small vocabulary to minimize miscommunication and to ensure that everyone involved (business, developers, testers, analysts and managers) are not only on the same page but using the same words.

Given, When, and Then are keywords utilized when writing JBehave scenarios. A scenario can have any number of steps and a story can contain many scenarios.

Given details the premises of the test, When details the exact incident, and Then details the expected outcome. To re-emphasize, the english readability is a novelty of BDD concepts.

Example of general story format:

Narrative:
In order to communicate effectively to the business some functionality
As a development team
I want to use Behaviour-Driven Development
     
Scenario:  A scenario is a collection of executable steps of different type
 
Given step represents a precondition to an event
When step represents the occurrence of the event
Then step represents the outcome of the event
 
Scenario:  Another scenario exploring different combination of events
 
Given a precondition
When a negative event occurs
Then a the outcome should be captured  


Integrating with Eclipse

Using the Eclipse Installer:

  1. Help > Install New Software...
  2. Add the new site location http://jbehave.org/reference/eclipse/updates/

  3. Select JBehave Eclipse feature and follow standard Eclipse installation procedure

Examples

Given a 5 by 5 game
When I toggle the cell at (3, 2)
Then the grid should look like
.....
.....
.....
..X..
.....
When I toggle the cell at (3, 1)
Then the grid should look like
.....
.....
.....
..X..
..X..
When I toggle the cell at (3, 2)
Then the grid should look like
.....
.....
.....
.....
..X..

This exhibits the simplicity of the language involved. Though it is a simple example, it is immediately readable and understandable even by those inexperienced in programming.

Specification: Stack

When a new stack is created
Then it is empty

When an element is added to the stack
Then that element is at the top of the stack

When a stack has N elements 
And element E is on top of the stack
Then a pop operation returns E
And the new size of the stack is N-1

Similarly, this tests a very simple data structure that can be quickly understood by those not well versed in the exact underworkings of how a stack functions; they only need to know the most basic outline of a stack in order to find this Story completely readable.

And finally, a more specific stack testing implementation:

Narrative:
In order to develop an application that requires a stack efficiently
As a development team
I would like to use an interface and implementation in Java directly
 
 
Scenario:  Basic functionality of a Stack
 
Given an empty stack
When the string Java is added
And the string C++ is added
And the last element is removed again
Then the resulting element should be Java
 
Scenario:  Stack search
 
Given an empty stack
When the string Java is added
And the string C++ is added
And the string PHP is added
And the element Java is searched for
Then the position returned should be 3

References

1. http://jbehave.org/
2. http://en.wikipedia.org/wiki/Behavior-driven_development
3. http://www.ryangreenhall.com/articles/bdd-by-example.html
4. http://behaviour-driven.org/
5. https://blog.codecentric.de/en/2011/03/automated-acceptance-testing-using-jbehave/