bdd in java and groovy - agile developer
TRANSCRIPT
![Page 1: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/1.jpg)
BDD IN JAVA AND GROOVY
speaker.identity { name 'Venkat Subramaniam' company 'Agile Developer, Inc.' credentials 'Programmer', 'Author', 'Trainer' blog 'http://agiledeveloper.com/blog' email '[email protected]'}
![Page 2: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/2.jpg)
Abstract
In this presentation we will take a look at what BDD is and look at tools to create them in Java and Groovy.
What's BDD?
Benefits of BDD
Tools for BDD
Creating BDD in Java
Creating BDD in Groovy
2
![Page 3: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/3.jpg)
Essence of AgilityTo create relevant working software
Developing software is hard business
How can you succeed?
Feedback is essential
Two kinds of feedbackCode Meets
Customer’sExpectations
CodeMeetsYour
Expectations
3
![Page 4: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/4.jpg)
Test Driven DevelopmentThe word "Test" in TDD is a bit misleading
It is not about verifying software
It is an approach to developing software by way of writing code that exercises your code
It helps you to
create a lightweight design
express behavior
create a form of highly expressive documentation
Keep an eye on code—to tell you if it begins to fall apart4
![Page 5: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/5.jpg)
Unit Testing: Essential but not Sufficient
Unit Testing is one (but not only) example of TDD
Unit Testing tells us that code's meeting the programmer's expectations
Very important to know the code continues to meet that expectation as software evolves to meet user's expectations
But, how do you know what's the user's expectations?
5
![Page 6: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/6.jpg)
Ways to express User's Expectations
Use cases
User Stories
Agile projects tend to lean towards user stories
Still, how to verify code continues to meet those expectations/requirements?
6
![Page 7: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/7.jpg)
Types of Tests and Levels
Code Meets
Customer’sExpectations
CodeMeetsYour
ExpectationsClasses/Models/...
Controls/Services/...
UI/Presentation/...
UnitTesting
FIT
BDD
SeleniumWatir
![Page 8: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/8.jpg)
Ubiquitous Language
"A language structured around the domain model and used by all team members to connect all the activities of the team with the software"—Domain Driven Design by Eric Evans.
8
![Page 9: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/9.jpg)
Executable DocumentationWe typically express requirements and system behavior in the form of documentation
What if you can actually execute that documentation?
You can show to yourself that the code is meeting the expectations
Helps you to ascertain that code continues to meet those expectations
Enter Behavior Driven Design
Introduced by Dan North9
![Page 10: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/10.jpg)
Behavior Driven Design
It is a TDD approach
It is a ubiquitous language
It is an executable documentation
It promotes communication
Helps develop common vocabulary and metaphor
Help you to get the "words" right
Can be used by programmers, testers, business analysts, domain experts, and customers.
10
![Page 11: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/11.jpg)
Behavior and Story
You can use BDD to express Stories and Behaviors
Story Framework and Spec Framework
Stories correspond to User Stories—to express behavior at application level
Spec or Behavior correspond to expectations at class level—to express behavior at service/component level
These can help express requirements that can be specified, understood, and negotiated by developers, testers, business analysts, and business customers.
11
![Page 12: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/12.jpg)
Behavior
Each behavior is expressed as a test/exercise method
It tells what the object should do
Notice the keyword "should"—that's a main focus in BDD—the shoulds and the shouldn’ts
12
![Page 13: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/13.jpg)
Building StoriesYou may define user stories as a series of acceptance criteria as scenarios
It has the givens, events, and outcomes
That is
Given some initial condition(s),
When event(s) occurs,
Then ensure some outcome(s)
13
![Page 14: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/14.jpg)
Executable Criteria
The specification is specified in a way it is executable
Directly represented in code and used to exercise your application code
14
![Page 15: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/15.jpg)
Tools for BDD
Java - JBehave, JDave, beanSpec, Instinct
easyb
15
![Page 16: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/16.jpg)
easyb
Started by Andy Glover
Express Story and Spec using Groovy Based Domain Specific Language (DSL)
Highly expressive
Can be used for Java and Groovy applications
16
![Page 17: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/17.jpg)
Writing a StoryA Story file can contain any number of scenarios
Each scenario has three parts: given, when, then
when is optional
17
Use " instead of ' if you want to embed expressions in text
![Page 18: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/18.jpg)
Writing a StoryYou can have more than one of given, when, then
When is optional
18
![Page 19: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/19.jpg)
Expressing Conditions–shouldYou can verify values on any object using one of the following should constructs
19
![Page 20: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/20.jpg)
ensuring (asserting)You can ensure or assert values using closure syntax
20
add multipleconditionsusing andoperates on value given to ensure
![Page 21: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/21.jpg)
Writing a SpecSpecs/Behaviors start with it
You can have as many of these you like in a Spec
21
![Page 22: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/22.jpg)
Story Example
22
file:money.story
Unintegrated or Pending Story
![Page 23: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/23.jpg)
Running Story
23
On my machine easyb is an alias to“java -classpath ... org.disco.easyb.BehaviorRunner”
You can provide multiple story files to easyb
![Page 24: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/24.jpg)
Fake Integration
24
![Page 25: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/25.jpg)
Integration
25
![Page 26: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/26.jpg)
AccountService.java
26Obviously a trivial example to get test pass, real
AccountService will be talking to Account(s)
![Page 27: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/27.jpg)
Running Story
27
![Page 28: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/28.jpg)
Let’s Break It
28Fix it and try again
![Page 29: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/29.jpg)
A Narrative
29
![Page 30: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/30.jpg)
Another Story
30
![Page 31: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/31.jpg)
Running The Two Stories
31
![Page 32: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/32.jpg)
Reports
32
![Page 33: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/33.jpg)
Reports
33
file: stories.txt
![Page 34: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/34.jpg)
Other Options to Run
Ant
Maven
IntelliJ IDEA
Refer to http://www.easyb.org
34
![Page 35: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/35.jpg)
Specifications
35
file: purchaseSoda.specification
![Page 36: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/36.jpg)
Referenceshttp://behavior-driven.org
http://jbehave.org/
http://codeforfun.wordpress.com/gspec/
http://www.easyb.org/
Domain-Driven Design: Tackling Complexity in the Heart of Software by Eric Evans, Addison-Wesley.
36
You can download examples and slides fromhttp://www.agiledeveloper.com - download
![Page 37: BDD IN JAVA AND GROOVY - Agile Developer](https://reader031.vdocument.in/reader031/viewer/2022021009/6203ad28da24ad121e4c2c1d/html5/thumbnails/37.jpg)
Thank You!Please fill in your session evaluations
37
You can download examples and slides fromhttp://www.agiledeveloper.com - download