+ All Categories
Home > Documents > An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime...

An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime...

Date post: 23-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
35
Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se 1 Code that matters An introduction to Behaviour-Driven Development
Transcript
Page 1: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se1

Code that matters

An introduction to Behaviour-Driven Development

Page 2: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se2

Agenda

• A little bit of background

• The challenge of doing the right thing

• Why TDD alone won't help

• Alternatives

• EasyB

Page 3: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se3

Bridging the gap ...

Page 4: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se4

Page 5: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se5

Page 6: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se6

Page 7: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se7

Page 8: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se8

Page 9: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se9

Page 10: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se10

Page 11: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se11

Card, Conversation, and Confirmation

"... a user story is a reminder tohave a conversation with your customer …"

Scott Ambler, Agile Modeling

Page 12: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se12

Page 13: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se13

TDD to the rescue?

Page 14: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se14

Page 15: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se15

"These are not the requirements the

business communicated to us!"

Page 16: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se16

TDD can help us build the system right, but it doesn't really help us build the right system.

Page 17: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se17

Low level, geeky format

TDD means ...

Page 18: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se18

All or nothing, red or green, ...

TDD means ...

Page 19: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se19

Working from the inside outstarting with the tiny details,

instead of the big picture

TDD means ...

Page 20: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se20

Business people wants to express the required behaviour, not necessarily write tests

Page 21: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se21

State required behaviour in a precise enough way, using the

vocabulary of the business

We want to ...

Page 22: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se22

State required behaviour using examples

We want to ...

Page 23: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se23

Gradually refine and evolve the examples, as the shared

understanding grows

We want to ...

Page 24: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se24

Work outside-in, starting with the overall scenarios that gives

business value

We want to ...

Page 25: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se25

Same, same, but different

• Close to the original notion of "Customer Tests"

• Known under different names:

– Test-driven Requirements

– Agile Acceptance Tests

– Behaviour Driven Development

Page 26: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se26

Lots of available tools and frameworks:

• FitNesse

• Text tool

• RSpec

• Cucumber

• Cuke4Duke

• EasyB

• ...

Page 27: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se27

easyb

• A BDD framework forthe Java platform

• Based on Groovy

Page 28: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se28

easyb in a nutshell: Story

• Use a natural language, narrative approach

• Describe precise requirements

• Usually made up of a set of scenarios

• Use an easy-to-understand structuregiven ”some context”when ”something happens”then ”something else should happen”

Page 29: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se29

Example User Story

White-collar time reporting 5

As a White-collar Employee

I want to record my working time

So that I get correctly calculated salary

Page 30: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se30

Example Task

Task: Regular days

Given a white-collar employee

When he arrives at 8:00 and leaves at 17:00

Then his result for that day is 0.

Page 31: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se31

Example Task

Task: Flex

Given a white-collar employee with flex

When he arrives at 8:00 and leaves at 18:00

Then his result for that day is +60.

Given a white-collar employee with flex

When he arrives at 8:00 and leaves at 16:00

Then his result for that day is -60.

Page 32: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se32

Example Task

Task: Overtime

Given a white-collar employee with flex and overtime

When he arrives at 8:00 and leaves at 19:00

Then his flex result for that day is +120

and his overtime is 0.

Given a white-collar employee with flex and overtime

When he arrives at 8:00 and leaves at 20:10

Then his flex result for that day is +120

and this overtime is +1,5.

Page 33: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se33

Demo

Page 34: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se35

To summarize:

• TDD can help us build the system right, but that is not enough

• TDR/ATDD/BDD can help us build the right system, by providing a slightly different perspective:

– State required behaviour using examples

– Gradually refine and evolve the examples

– Work from the outside-in

• easyb is a bdd framework for the Java platform, that leverages the power and beauty of Groovy

Page 35: An introduction to Behaviour-Driven Development · 2020. 6. 18. · Example Task Task: Overtime Given a white-collar employee with flex and overtime When he arrives at 8:00 and leaves

Code that matters © 2011 Callista Enterprise | www.callistaenterprise.se36

Time for Questions!


Recommended