the lazy developer's guide to bdd (with cucumber)

108
A LAZY Developer's Guide to BDD (with ) ~ Ng Tze Yang (aka TY)

Upload: tze-yang-ng

Post on 14-May-2015

4.235 views

Category:

Technology


2 download

DESCRIPTION

The slides for my presentation at GeekCamp.sg 2009.

TRANSCRIPT

Page 1: The LAZY Developer's Guide to BDD (with Cucumber)

A LAZY Developer's Guide to BDD

(with )~ Ng Tze Yang (aka TY)

Page 2: The LAZY Developer's Guide to BDD (with Cucumber)

2

Everyone gets a little of 's ♥

2 weeks ago, i changed it to:

Page 3: The LAZY Developer's Guide to BDD (with Cucumber)

3

A LAZY Developer's Guide to BDD

(with )

Page 4: The LAZY Developer's Guide to BDD (with Cucumber)

4

WTF is “LAZY” ??

Page 5: The LAZY Developer's Guide to BDD (with Cucumber)

5

LAZY= !(TATFT)

Page 6: The LAZY Developer's Guide to BDD (with Cucumber)

6

WTF is “TATFT” ??

Page 7: The LAZY Developer's Guide to BDD (with Cucumber)

7

Page 8: The LAZY Developer's Guide to BDD (with Cucumber)

8

Why Not TATFT ??

Page 9: The LAZY Developer's Guide to BDD (with Cucumber)

9

Why Not TATFT ??

* What is most important for a software ??

Page 10: The LAZY Developer's Guide to BDD (with Cucumber)

10

Why Not TATFT ??

* What is most important for a software ??

=> Business Value

Page 11: The LAZY Developer's Guide to BDD (with Cucumber)

11

Why Not TATFT ??

* What is most important for a software ??

=> Business Value

* How do we quantify BV ??

Page 12: The LAZY Developer's Guide to BDD (with Cucumber)

12

Why Not TATFT ??

* What is most important for a software ??

=> Business Value

* How do we quantify BV ??

=> Behaviours

Page 13: The LAZY Developer's Guide to BDD (with Cucumber)

13

BDD~ Behaviour Driven Development ~

Page 14: The LAZY Developer's Guide to BDD (with Cucumber)

14

BDD~ Behaviour Driven Development ~

“BDD facilitates agile development, which is an approach to develop functional

software, within reasonable timeline, making everyone happy, without killing anyone, or

burning down any bank.”

Page 15: The LAZY Developer's Guide to BDD (with Cucumber)

15

BDD's Core Principles

Page 16: The LAZY Developer's Guide to BDD (with Cucumber)

16

BDD's Core Principles

* It's all behaviour

“ The business & technology people should be speaking the same words

when referring to the same idea, there should not be any translator.”

Page 17: The LAZY Developer's Guide to BDD (with Cucumber)

17

BDD's Core Principles

* It's all behaviour

Behaviour: the addition of N values should yield the summation of them

Example: the addition of 2 + 4 +1 should yield 8

Page 18: The LAZY Developer's Guide to BDD (with Cucumber)

18

BDD's Core Principles

* It's all behaviour

* Deliver stakeholder value

“ Whatever u are doing, it should be delivering business value, or increasing ur ability to deliver value, if the activity

doesn't acheive this, stop doing it”

Page 19: The LAZY Developer's Guide to BDD (with Cucumber)

19

BDD's Core Principles

* It's all behaviour

* Deliver stakeholder value

“ Unit testing is important, as it makesrefactoring & regression testing easier, which eases maintenace and enhance ur ability to

deliver newer features faster”

Page 20: The LAZY Developer's Guide to BDD (with Cucumber)

20

BDD's Core Principles

* It's all behaviour

* Deliver stakeholder value

* Enough is enough

“ Do not overengineer, do not overdo upfront planning, analysis and design.

Do just enough to get things started in the right direction”

Page 21: The LAZY Developer's Guide to BDD (with Cucumber)

21

BDD's Core Principles

* It's all behaviour

* Deliver stakeholder value

* Enough is enough

“ When i wanna go to sentosa from my AMKhome, i just goto gothere.sg to do a quick

check, and that's good enough, i don't needto get down to switching lanes on CTE,

blah blah. ”

Page 22: The LAZY Developer's Guide to BDD (with Cucumber)

22

Cucumber ? Nice to Eat ?!

Page 23: The LAZY Developer's Guide to BDD (with Cucumber)

23

Cucumber ? Nice to Eat ?!

* a tool for functional testing

Page 24: The LAZY Developer's Guide to BDD (with Cucumber)

24

Cucumber ? Nice to Eat ?!

* a tool for functional testing

* by Aslak HellesØy, & many other nice people

Page 25: The LAZY Developer's Guide to BDD (with Cucumber)

25

Cucumber ? Nice to Eat ?!

* a tool for functional testing

* allows non-technies to express app's functions in plain text

* by Aslak HellesØy, & many other nice people

Page 26: The LAZY Developer's Guide to BDD (with Cucumber)

26

Cucumber ? Nice to Eat ?!

* a tool for functional testing

* allows non-technies to express app's functions in plain text

* plain text serves as documentation & executable examples

* by Aslak HellesØy, & many other nice people

Page 27: The LAZY Developer's Guide to BDD (with Cucumber)

27

Hmm .. Plain Text ?!

Page 28: The LAZY Developer's Guide to BDD (with Cucumber)

28

A Prettier Plain Text

Page 29: The LAZY Developer's Guide to BDD (with Cucumber)

29

The Title

Page 30: The LAZY Developer's Guide to BDD (with Cucumber)

30

The Narrative

Page 31: The LAZY Developer's Guide to BDD (with Cucumber)

31

Guideline for the Narrative

Page 32: The LAZY Developer's Guide to BDD (with Cucumber)

32

Guideline for the Narrative

* identify the stakeholder

“ Eg. The system administrator”

Page 33: The LAZY Developer's Guide to BDD (with Cucumber)

33

Guideline for the Narrative

* identify the stakeholder

* describe the feature he wants

“ Eg. Trashing of all invalid purchase orders in the system”

Page 34: The LAZY Developer's Guide to BDD (with Cucumber)

34

Guideline for the Narrative

* identify the stakeholder

* describe the feature he wants

* the reason for wanting it

“ Eg. Prevent data corruption”

Page 35: The LAZY Developer's Guide to BDD (with Cucumber)

35

The Acceptance Criterion

Page 36: The LAZY Developer's Guide to BDD (with Cucumber)

36

The Scenario's Title

Page 37: The LAZY Developer's Guide to BDD (with Cucumber)

37

The Scenario's Steps

Page 38: The LAZY Developer's Guide to BDD (with Cucumber)

38

Given | When | Then

Page 39: The LAZY Developer's Guide to BDD (with Cucumber)

39

Given | When | Then

* GIVEN ... setting up system to a known state

“ Eg 1. Database setup ...Given the following users already exists”

“ Eg 2. Visiting a Url ...Given I am on users management page”

“ Eg 3. Ensure User's Login ...Given I already login as “HappyMan””

Page 40: The LAZY Developer's Guide to BDD (with Cucumber)

40

Given | When | Then

* GIVEN ... setting up system to a known state

* WHEN ... exercising an event

“ Eg. Pressing Button ...When I press “Help Me””

Page 41: The LAZY Developer's Guide to BDD (with Cucumber)

41

Given | When | Then

* GIVEN ... setting up system to a known state

* WHEN ... exercising an event

* THEN ... verifying an outcome

“ Eg. Seeing a message ...Then I should see “Login Successful””

Page 42: The LAZY Developer's Guide to BDD (with Cucumber)

42

Save & Execute It !!

<PROJECT_ROOT> `~ features/ `- sign_up.feature

* Save at:

Page 43: The LAZY Developer's Guide to BDD (with Cucumber)

43

Save & Execute It !!

<PROJECT_ROOT> `~ features/ `- sign_up.feature

* Run with: #$ cucumber features

* Save at:

Page 44: The LAZY Developer's Guide to BDD (with Cucumber)

44

P1

P2

Page 45: The LAZY Developer's Guide to BDD (with Cucumber)

45

Page 46: The LAZY Developer's Guide to BDD (with Cucumber)

46

Page 47: The LAZY Developer's Guide to BDD (with Cucumber)

47

Page 48: The LAZY Developer's Guide to BDD (with Cucumber)

48

Page 49: The LAZY Developer's Guide to BDD (with Cucumber)

49

Page 50: The LAZY Developer's Guide to BDD (with Cucumber)

50

Page 51: The LAZY Developer's Guide to BDD (with Cucumber)

51

Page 52: The LAZY Developer's Guide to BDD (with Cucumber)

52

Step Definitions

Page 53: The LAZY Developer's Guide to BDD (with Cucumber)

53

Save & Execute It !!

<PROJECT_ROOT> `~ features/ `- steps.rb

* Save as:

Page 54: The LAZY Developer's Guide to BDD (with Cucumber)

54

Save & Execute It !!

<PROJECT_ROOT> `~ features/ `- steps.rb

* Save as:

* Run with: #$ cucumber features

Page 55: The LAZY Developer's Guide to BDD (with Cucumber)

55

Page 56: The LAZY Developer's Guide to BDD (with Cucumber)

56

Page 57: The LAZY Developer's Guide to BDD (with Cucumber)

57

Page 58: The LAZY Developer's Guide to BDD (with Cucumber)

58

The Functional Test Model

Page 59: The LAZY Developer's Guide to BDD (with Cucumber)

59

The Generic Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Page 60: The LAZY Developer's Guide to BDD (with Cucumber)

60

The Generic Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Target App

Page 61: The LAZY Developer's Guide to BDD (with Cucumber)

61

The Generic Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Target App

Driver

Page 62: The LAZY Developer's Guide to BDD (with Cucumber)

62

The Generic Webapp Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Page 63: The LAZY Developer's Guide to BDD (with Cucumber)

63

The Generic Webapp Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Webapp* web server* deployed app* web browser

Page 64: The LAZY Developer's Guide to BDD (with Cucumber)

64

The Generic Webapp Model

Cucumber* cucumber exec* features/*.feature* features/*.rb

Webapp* web server* deployed files* web browser

Driver* selenium (server+client)

Page 65: The LAZY Developer's Guide to BDD (with Cucumber)

65

FAST FOWARD(Completed: Step Definitions)

Page 66: The LAZY Developer's Guide to BDD (with Cucumber)

66

Before

After

Page 67: The LAZY Developer's Guide to BDD (with Cucumber)

67

Before

After

Page 68: The LAZY Developer's Guide to BDD (with Cucumber)

68

Before

After

Page 69: The LAZY Developer's Guide to BDD (with Cucumber)

69

Before

After

Page 70: The LAZY Developer's Guide to BDD (with Cucumber)

70

Before

After

Page 71: The LAZY Developer's Guide to BDD (with Cucumber)

71

A New *.rb File

<PROJECT_ROOT> `~ features/ `- selenium.rb

Page 72: The LAZY Developer's Guide to BDD (with Cucumber)

72

Page 73: The LAZY Developer's Guide to BDD (with Cucumber)

73

Page 74: The LAZY Developer's Guide to BDD (with Cucumber)

74

Page 75: The LAZY Developer's Guide to BDD (with Cucumber)

75

Page 76: The LAZY Developer's Guide to BDD (with Cucumber)

76

Page 77: The LAZY Developer's Guide to BDD (with Cucumber)

77

OK, Let's Run It !!

#$ cucumber features

Page 78: The LAZY Developer's Guide to BDD (with Cucumber)

78

Page 79: The LAZY Developer's Guide to BDD (with Cucumber)

79

Page 80: The LAZY Developer's Guide to BDD (with Cucumber)

80

Run Selenium Server

#$ selenium

Page 81: The LAZY Developer's Guide to BDD (with Cucumber)

81

Run Selenium Server

#$ selenium

Page 82: The LAZY Developer's Guide to BDD (with Cucumber)

82

Page 83: The LAZY Developer's Guide to BDD (with Cucumber)

83

Let's Try Again

#$ cucumber features

Page 84: The LAZY Developer's Guide to BDD (with Cucumber)

84

Page 85: The LAZY Developer's Guide to BDD (with Cucumber)

85

Page 86: The LAZY Developer's Guide to BDD (with Cucumber)

86

The Missing Part ??

~ Our Application ~

Page 87: The LAZY Developer's Guide to BDD (with Cucumber)

87

FAST FOWARD AGAIN(Completed: Application)

Page 88: The LAZY Developer's Guide to BDD (with Cucumber)

88

Let's Run the Webapp

#$ ruby app.rb

Page 89: The LAZY Developer's Guide to BDD (with Cucumber)

89

Let's Run the Webapp

#$ ruby app.rb

Page 90: The LAZY Developer's Guide to BDD (with Cucumber)

90

Page 91: The LAZY Developer's Guide to BDD (with Cucumber)

91

Let's Try Once Again

#$ cucumber features

Page 92: The LAZY Developer's Guide to BDD (with Cucumber)

92

Let's Try Once Again

#$ cucumber features

Page 93: The LAZY Developer's Guide to BDD (with Cucumber)

93

Revision Time

Page 94: The LAZY Developer's Guide to BDD (with Cucumber)

94

Summing Up

1) Capturing user's requirements in a feature file

Page 95: The LAZY Developer's Guide to BDD (with Cucumber)

95

Feature's Title

Page 96: The LAZY Developer's Guide to BDD (with Cucumber)

96

Feature's Narrative

Page 97: The LAZY Developer's Guide to BDD (with Cucumber)

97

Feature's Narrative

Page 98: The LAZY Developer's Guide to BDD (with Cucumber)

98

Feature's Narrative

Page 99: The LAZY Developer's Guide to BDD (with Cucumber)

99

Feature's Narrative

Page 100: The LAZY Developer's Guide to BDD (with Cucumber)

100

Feature's Acceptance Criterion

Page 101: The LAZY Developer's Guide to BDD (with Cucumber)

101

Feature's Acceptance Criterion

Page 102: The LAZY Developer's Guide to BDD (with Cucumber)

102

Feature's Acceptance Criterion

Page 103: The LAZY Developer's Guide to BDD (with Cucumber)

103

Summing Up

2) Complete the missing step defintions

1) Capturing user's requirements in a feature file

Page 104: The LAZY Developer's Guide to BDD (with Cucumber)

104

Step Definitions

Page 105: The LAZY Developer's Guide to BDD (with Cucumber)

105

Summing Up

3) Implement the application

1) Capturing user's requirements in a feature file

2) Complete the missing step defintions

Page 106: The LAZY Developer's Guide to BDD (with Cucumber)

106

Useful Links

* Cucumber's Wiki http://wiki.github.com/aslakhellesoy/cucumber

* Cucumber's Homepage http://cukes.info/

* BDD @ Wikipedia

Page 107: The LAZY Developer's Guide to BDD (with Cucumber)

107

Recommended Video

Page 108: The LAZY Developer's Guide to BDD (with Cucumber)

108

THE END