Beruflich Dokumente
Kultur Dokumente
I had a problem. While using and teaching agile practices like test-driven development (TDD) on projects in different environments. Programmers wanted to know where to start, what to test and what not to test, how much to test in one go, what to call their tests, and how to understand why a test fails.
What is BDD?
BDD is a synthesis and refinement of practices stemming from TDD (Test Driven Development) and ATDD (Acceptance Test Driven Development). It is about implementing an application by describing it from the point of view of its stakeholders. Stories Scenarios and Steps
Principles of BDD
Unit test names be whole sentences starting with the word "should" and should be written in order of business value. Acceptance tests should be written using the standard agile framework of a User story: "As a [role] I want [feature] so that [benefit]". Acceptance criteria should be written in terms of scenarios and implemented as classes: Given [initial context], when [event occurs], then [ensure some outcomes].
User Stories
User Stories
Series of acceptance criteria Called scenarios Each scenario has givens, events and outcomes Used in Agile projects
Behaviour
Narrative
BDD Process
Customer Domain Expert QA Developer
Stories
Matches to
Behaviour
Application
BDD Process
4.
5. 6. 7.
For each scenario describing a feature Run the scenario it fails (go red) Define the first step go red Write down the application code getting the step to pass go green Refactor the code and repeat steps 4 & 5 for each step until 6 The scenario passes go green Refactor the application code
Narrative
Describe the intent of the story
Narrative: In order to communicate effectively to the business functionality As a development team member I want to use Behaviour-Driven Development
Scenario
The intent of the scenario
Narrative: In order to communicate effectively to the business functionality As a development team member I want to use Behaviour-Driven Development
Steps
Given,When,Then The Gherkin Style
Narrative: In order to communicate effectively to the business functionality As a development team member I want to use Behaviour-Driven Development
Scenario: A scenario is a collection of executable steps of different type Given some initial context (the givens), When an event occurs, Then ensure some outcomes (the assertions)
10
BDD Tools
C
Cspec C++ CppSpec, Spec-CPP .Net NBehave, NSpecify, SpecFlow Groovy GSpec, easyb, Cuke4Duke PHP PHPSpec Python Specipy Ruby RSpec, Shoulda, Cucumber More
11
JBehave Java annotations based, Test frameworks agnostic Cuke4duke Cucumber support for JVM JDave RSpec (Ruby) inspired, Mojo 2 & Hamcrest based beanSpec Java based easyb Java based, Specifications written in Groovy instinct BDD framework for Java, providing annotations for contexts. Inspired by Rspec BDoc - Extracts behaviour from unit tests
12
BDD
Test Driven Development
JBehave
14
Jbehave features
Pure Java implementation Text-based user stories Annotation-based binding of textual steps to Java methods DI support (Spring, Guice, Pico, Weld) Story reporting (HTML, TXT, XML) User stories localization IDE integration Ant and Maven integration Test frameworks agnostic (JUnit, hamcrest, etc.)
15
Extension of JBehave providing web integration layer for BDD Features: JBehave Queue allows generic stories to be
run asynchronously
synchronously
Web
Selenium
16
Jbehave
17
Syntax highlighting Step hyperlink detection and link to corresponding Java method Step autocompletion Step validation, detecting both unimplemented steps and ambiguous steps, i.e. matching multiple methods Etc.
http://jbehave.org/reference/eclipse/updates/
18
Demo Time!
Example
Narrative: In order to make some rapid calculation As a user I want to make some additions Scenario: basic Addition Given I takes the first value 1 And I takes the second value 2 When I add the two values 1 and 2 Then I have 3
20