introduction to tdd and bdd

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

Upload: luis-garcia-castro

Post on 14-Apr-2017

128 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Introduction to TDD and BDD

INTRODUCTION TO BDD(Behaviour-Driven Development)

Luis García Castro

Page 2: Introduction to TDD and BDD

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

Page 3: Introduction to TDD and BDD

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

Page 4: Introduction to TDD and BDD

4

What is TDD ?

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

Page 5: Introduction to TDD and BDD

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

Page 6: Introduction to TDD and BDD

Acceptance testsCustomer tests

BDD

Unit testsTDD

SonarLint...

6

Is it enough with unit tests ?

Code Right vs Right Code

Page 7: Introduction to TDD and BDD

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

Page 8: Introduction to TDD and BDD

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

Page 9: Introduction to TDD and BDD

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

Page 10: Introduction to TDD and BDD

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

Page 11: Introduction to TDD and BDD

11

BDD is about Comunication

Business

Team

Requirements

Examples to discuss

Design and createcode specification

Examples toimplement

Page 12: Introduction to TDD and BDD

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

Page 13: Introduction to TDD and BDD

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, ...

Page 14: Introduction to TDD and BDD

14

Gherkin examples

Page 15: Introduction to TDD and BDD

15

Main benefits of BDD

● Examples become unit tests and documentation

● Scenarios become acceptance tests and documentation

● Acceptance tests also become regression tests

Page 16: Introduction to TDD and BDD

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

Page 17: Introduction to TDD and BDD

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

Page 18: Introduction to TDD and BDD

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

Page 19: Introduction to TDD and BDD

19

BDD + TDD Cycle

Page 20: Introduction to TDD and BDD

20

Testing Pyramid

Page 21: Introduction to TDD and BDD

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

Page 22: Introduction to TDD and BDD

22

Questions ?