Slide 1

Slide 1 text

INTRODUCTION TO BDD (Behaviour-Driven Development) Luis García Castro

Slide 2

Slide 2 text

TESTING 2 Why is testing so important ? We can’t avoid to have bugs in our applications, but we must limit its presence and impact (and not only in release date) Inception Design Development Acceptance Maintenance

Slide 3

Slide 3 text

3 Benefits of Unit Testing Tests create a feedback loop that informs the developer whether the product is working or not. ● Unit tests are fast ● Unit tests are reliable ● Unit tests isolate failures But tests made at the end of the project are only useful to exceed the mandatory coverage, they don’t provide many other benefits

Slide 4

Slide 4 text

4 What is TDD ? TDD is a not just “adding tests first”, it’s a workflow

Slide 5

Slide 5 text

5 Benefits of TDD TDD is the best way to discover how complex your code is becoming ● Do you need to mock 7 objects for a unit test? ● Do you have a setup method of >15 lines? ● Are you able to test all your code? By writing test first: ● You are becoming a consumer of your own API ● You are forced to think what responsibilities the given object should have ● You are creating a safety net for everyone

Slide 6

Slide 6 text

Acceptance tests Customer tests … BDD Unit tests TDD Sonar Lint ... 6 Is it enough with unit tests ? Code Right vs Right Code

Slide 7

Slide 7 text

7 What is BDD ? Behaviour-Driven Development “It’s about focusing on the behaviour of an application from the point of view of its stakeholders” Dan North

Slide 8

Slide 8 text

8 Who is a stakeholder ? A stakeholder is anyone who cares about: ● What the application does ● How much it costs ● Whether it is secure ● Whether the network will hold ● Whether it complies with the law ● How easy it is to deploy and diagnose ● How well it is written and architected ● How easy it is to change

Slide 9

Slide 9 text

9 A more formal definition of BDD BDD is a second-generation, outside-in, pull-based, multiple- stakeholder, multiple-scale, high-automation, agile methodology It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters Dan North

Slide 10

Slide 10 text

10 BDD asks for an Outside-In approach Express a requirement as a Story ● As… I want… So that I… Define acceptance criteria as scenarios made up of steps ● Given… When… Then... Automate the scenarios ● So each step becomes running code

Slide 11

Slide 11 text

11 BDD is about Comunication Business Team Requirements Examples to discuss Design and create code specification Examples to implement

Slide 12

Slide 12 text

12 Simple requirements and examples Feature: Tracking deliveries As a Customer I want to see a status of my delivery So I can know when it’s going to be delivered Scenario: Clicking a tracking URL Given I am waiting for a delivery And I received a confirmation message When I click the tracking URL from the message Then I should see a status of my delivery

Slide 13

Slide 13 text

13 Gherkin Gherkin is plain-text English (or any other of the 60+ supported languages) with a little extra structure. Is designed to be easy to learn by non-programmers, yet structured enough to allow concise description of examples to illustrate business rules in most real-world domains. In Gherkin each not-blank line should start with a keyword: Feature, Scenario, Given, When, Then, And, Background, ...

Slide 14

Slide 14 text

14 Gherkin examples

Slide 15

Slide 15 text

15 Main benefits of BDD ● Examples become unit tests and documentation ● Scenarios become acceptance tests and documentation ● Acceptance tests also become regression tests

Slide 16

Slide 16 text

16 Benefits of BDD for developers ● BDD will help you focus ● BDD will give you confidence to refactor ● BDD will help you better undersand the customers needs

Slide 17

Slide 17 text

17 Benefits of BDD for Product Owners ● BDD will give you a greater insight into the complexity of what you’re asking for ● BDD will give you transparency about what the team is doing in each iteration ● BDD will help your teams ship faster

Slide 18

Slide 18 text

18 Benefits of BDD for Testers ● BDD will mean you can find bugs even before they have been written ● BDD will give you the best automatic regression tests ● BDD will free you to do interesting, creative, exploratory testing

Slide 19

Slide 19 text

19 BDD + TDD Cycle

Slide 20

Slide 20 text

20 Testing Pyramid

Slide 21

Slide 21 text

21 Use BDD in almost any language ● Java ● Concordion ● Easyb ● JDave ● JBehave ● Javascript ● Protractor ● Jasmine ● Cucumber ● Python ● Behave ● Groovy ● Cucumber ● PHP ● Kahlan ● Behat ● .NET ● Concordion

Slide 22

Slide 22 text

22 Questions ?