why you should be doing bdd

31
1 WHY YOU SHOULD BE DOING BDD MATEUSZ ZALEWSKI @mpzalewski https://github.com/Zales0123

Upload: mateusz-zalewski

Post on 15-Feb-2017

479 views

Category:

Software


1 download

TRANSCRIPT

1

WHY YOU SHOULD BE DOING BDD

MATEUSZ ZALEWSKI

@mpzalewski

https://github.com/Zales0123

BDD is a process designed to aid the management and the delivery of software development projects by improving communication between engineers and

business professionals.

BEHAVIOR DRIVEN DEVELOPMENT

2

http://inviqa.com/insights/bdd-guide

3

TEST BEHAVIOR

https://worldviewofjesus.files.wordpress.com/2015/02/evolution.jpg

4

✦ “There is no time”

✦ “It’s unnecessary extra code”

✦ “I know what I’m writing”

✦ “Client wants visible effect”

✦ and many more…

BENEFITS

5

COMMUNICATION

6

REQUIREMENTS CODE

7

कोड байт

MONEY CODE BYTE

8

कोड байт

MONEY CODE BYTE

UBIQUITOUS LANGUAGE

Valu

e

Time

9

NOEFFICIENCY

Valu

e

Time

10

EFFICIENCY

HOW?

11

FAILING

PASSEDREFACTOR

12

NO TESTS

NO REFACTORING

13

14

GOAL

We are going to increase sale by

selling more products

We are going to increase sale by

selling more products

GOAL

We are planning to achieve a 10% increase in sale in our web store

in 4 months

15

EXAMPLES

Given "PHP T-Shirt" is priced at €100.00

And the store has "VAT" tax rate of 23%

When I add product "PHP T-Shirt" to the cart

Then my cart taxes should be €23.00

16

LESS AMBIGUITY =

LESS MISUNDERSTANDINGS

17

18

SPECIFICATION

STORY

How class should work

Application business logic

DON’T TEST, DESCRIBE

19

20

✦ it adds two numbers

✦ it multiplies two numbers

✦ it subtracts two numbers

✦ it divides two numbers

✦ it not allows to divide by 0

WHAT DOES CALCULATOR DO?

21

HOW HARD CAN IT BE?

class CalculatorSpec extends ObjectBehavior { function it_adds_two_numbers() { $this->add(4, 5)->shouldReturn(9); }

function it_multiplies_two_numbers() { $this->multiply(3, 8)->shouldReturn(24); } function it_does_not_allow_to_divide_by_0() { $this ->shouldThrow(‘\InvalidArgumentException’) ->during(‘divide’, [10, 0]) ; } }

22

class ValidationMessageProviderSpec extends ObjectBehavior { function it_provides_happy_message_if_validation_passed( Validator $validator, ValidatedObject $object ) { $validator->validate($object)->willReturn(true); $this->provide($object)->shouldReturn(‘Great! Everything is fine!’); } }

HAVING FUN WITH MOCKS

THINK IN CODE

CODE IS GOOD

23

http://phpsrbija.rs/tday2014/img/portfolio/phpspec.png

STORY

24

It is an ancient need to be told stories. But the story needs a great storyteller.

~ Alan Rickman

FEATURE

25

WHY? (BUSINESS VALUE)

WHO? (BENEFICIARY)

WHAT? (FEATURE DESCRIPTION)

FEATURE

26

In order to pay less while buying goods

As a Customer

I want to receive discount for my purchase

Receiving percentage discount promotion on order

SCENARIO

27

Given "PHP T-Shirt" is priced at €100.00

And the store has "VAT" tax rate of 23%

When I add product "PHP T-Shirt" to the cart

Then my cart taxes should be €23.00

BEHAT28

https://github.com/Behat/Behat

✦ uses Gherkin structured language

✦ used to describe application business logic

✦ really impressive

29

✦ Behat (PHP)

✦ PHPSpec (PHP)

✦ Cucumber (Ruby)

✦ JBehave (Java)

✦ Spock (Groovy)

✦ SpecFlow (.NET)

TOOLS

30

Have no fear of perfection - you’ll never reach it.~ Salvador Dali

THANK YOU

31

@mpzalewskihttps://github.com/Zales0123