-
What is BDD?
- Emerged from TDD
- TDD + Domain Driven Design
- What is Domain Driven Design?
- What is domain?
- sphere of knowledge
- sphere of influence
- sphere of activity
- subject area to which user applied a particular software
- Example: Banking domain
- Railway Reservation
- Residential building
- What is Ubiquitous Language?
- Common language shared between developers and business which must be in business terminology
- What is domain?
- What is Domain Driven Design?
- We use simple Domain-Specific-Language (DSL) formed from natural language constructs to express behavior and expected outcomes
- What is DSL?
- Computer language specialized to an application domain
- Example: For web pages, we use HTML
- Example: Emacs Lisp for GNU Emacs and XEmacs
- Computer language specialized to an application domain
- What is DSL?
-
How is BDD related to TDD?
- TDD:
- For each unit of software,
- define test set for the unit
- implement the unit
- verify that implementation of unit makes the test succeed
- For each unit of software,
- BDD:
- Test of a unit should be specified in terms of desired behavior of the unit
- Desired behavior: business requirements (which has business value)
- It is an outside-in activity
- Test of a unit should be specified in terms of desired behavior of the unit
- TDD:
-
What is the purpose of BDD?
- It is used to tie business requirements that add business value to the unit tests and the units tests are ultimately tied to the software implementation
-
How to specify BDD?
-
Who should work on this?
- Business analysts and Developers
-
Behavior should be specified in terms of user stories
-
Structure:
Title: Clear explicit title. Narrative Introduction which should contain * who (business/project role) is the driver/ primary stake holder of story (actor who derives business benefit from story) * what effect stakeholder wants the story to have * what business value does stake holder derive from this Acceptance criteria/ scenarios description of each case of narrative. A scenario should have the structure * Specifies initial condition assumed to be true. (Single clause/ several clauses) * Event that triggers the start of the scenario * States expected outcome -
How to write stories is not defined
-
Dan North template
Story: Returns go to stock In order to keep track of stock As a store owner I want to add items back to stock when they're returned Scenario 1: Refunded items should be returned to stock Given that a customer previously bought a black sweater from me And I have three black sweaters in stock. When he returns the black sweater for refund Then I should have four black sweaters in stock. Scenario 2: Replaced items should be returned to stock Given that a customer previosly brought a blue garment from me And I have two blue garments in stock And three black garments in stock. When he returns the blue garment for a replacement in black Then I should have three blue garments in stock And two black garments in stock.
-
-
What is Ubiquitous Language and how is it related to BDD?
- It is a semi-formal language shared by all members of software development team (technical and non-technical team members)
- It is used to write user stories to identify
- stakeholder
- business effect
- business value
- It is used to describe different scenarios with preconditions, trigger, expected outcomes
-
Give an example of BDD implementation for Java Software?
- Processing by tool in general
- Reads specification
- Formal parts of ubiquitous language are interpreted (Given, When, Then) and breaks scenario into clauses
- Clause is transformed into parameter for test of user story
- Test is executed for each scenario by using parameters from the scenario
- JBehave (Developed by Dan North)
-
Input Document for JBehave
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..- Given: defines start of a scenario
- When: Trigger
- Then: Outcome of action following trigger
-
JBehave parses text file and sets up clauses
-
Code to write by developers
private Game game; private StringRenderer renderer; @Given("a $width by $height game") public void theGameIsRunning(int width, int height) { game = new Game(width, height); renderer = new StringRenderer(); game.setObserver(renderer); } @When("I toggle the cell at ($column, $row)") public void iToggleTheCellAt(int column, int row) { game.toggleCellAt(column, row); } @Then("the grid should look like $grid") public void theGridShouldLookLike(String grid) { assertThat(renderer.asString(), equalTo(grid)); } -
JBehave can pick terms from templates and pass them to methods in test code
-
- Processing by tool in general
-
How is a specification different from Story?
- Specification:
-
Example: RSpec
describe Hash do let(:hash) { Hash[:hello, 'world']} it { expect(Hash.new).to eq{}} it "hashes the correct information in a key" do expect(hash[:hello]).to eq('world') end it "includes key" do hash.key.include?(:hello).should be true end end -
use of functional specification (technical in nature)
-
Defines specific behavior of component being tested
-
Can be implemented at lower level
-
- Specification: