SlideShare a Scribd company logo
BDD + Lambdaj
Andreas Enbohm, Capgemini
@enbohm
BDD
• Behavior-driven development (BDD) is an
increasingly popular variation on test-driven
development, which helps developers think
more in terms of “executable specifications”
than in terms of conventional tests
Why use BDD?
• Only build feature that add real value
• Less wasted effort
• Better communication
• Higher quality, better tested product
• Traceability
BDD
• BDD describes TDD done well
- removes word ’test’
- replace it with
behaviour, examples, scenarios etc.
• Good habits;
1. Working outside-in
2. Using examples to clarify requirements
(scenarios)
3. Using a common (ubiquitous) language
BDD – Value Driven
• A good goal should add value to business
- increase revenue
- reduce cost
- avoid future cost
- protect revenue
”Increase revenue by allowing
customers to…”
”Prevent current customers
switching to competing product
by …”
BDD – What Does the Customer Need?
• Good teams push back!
- users tend to express requirements as implementations
- we need to find the business need!
We need caching
Why?
So that the page
loads fast
So that the
customer will buy
stuff on our site and
doesn’t leave page
Why?
Ok, so to increase the chance a customer
will buy [stuff] it need to be ’fast’. Caching
might be one way to achive this, but
compressing images might be more
effective. Or another way might be
loaders, or ..
BDD – Better understanding
• Working outside-in
- if you need to explain to a computer how to check the
requirement, you’ll need to be damn sure understand it
yourself
• Business black-box testing is often done manually!
- BDD enables automated acceptance testing
• Mininum effort /code to fulfull requirement
BDD – Common Language
• Common Language
- communication often the biggest overhead
- even bigger if you allow different dialects of terminology
- takes time but gains significant advantage
BDD
BDD
BDD - Stories
Story: Basic Purchase flow - User purchases a Grundpaket (id 21)
Narrative:
In order to attract new CDK customers
As a leading channel reseller
I want to provide an easy way to buy our products through our website
Goal come first
Stakeholder is
secondary
The feature must be
required to achieve this
goal
BDD - Scenarios
• The ’perfect’ bridge between the business-
facing and technology-facing sides of a team
Scenario: User selects a channel package for purchase (id 21.2)
Given address search is done with address street Hantverkaregatan streetNo 28 and city
Helsingborg on page url http://...
When user select totalpaketet by clicking on choose button
Then the user starts a purchase flow where the first step is called Grundpaket och box is
shown
Common language which is
reflected all way down in the
code
BDD - Java
• CDK use Jbehave
- lots of documentation
- uses Gherkin language
BDD - Implementation
BDD – CDK Implementation
• No stories/scenarion from start
- Emma wrote a lot of BDD stories
- used by CDK as ’lightweight’ acceptance test
• Selenium
- browser automation
• Spring as embedded runner
- gives us DI
• Page template patterns (see code)
BDD – CDK Implementation
• Pros
- another way of thinking of test
- sentence instead of test (even for our Junit
tests)
- we could make our major refactoring with
confidence
• Cons
- selenium (engines)
- issus/bugs with JBehave (fetching
parameters, mapping to POJO)
- we should not come up with the goal
BDD
• Reports show 75%* less bugs and 30%* faster
to production
Lambdaj
• An internal DSL to manipulate collections
without loops
• Large part of business logic is always the
same; iteration over collections of business
objects to do a set of tasks
• Loops (especially nested and mixed with
conditions) are hard to read that to be written
• for loop is inherently serial
Lambdaj
• Business logic should be less technical and
closer to business fashion
Lambdaj
• Iterate over collections in order to:
- select
- aggregate
- sort
- filter
- group
- extract
- and more..
Lambdaj - Sort
List<Person> sortedByAgePersons = sort(persons, on(Person.class).getAge());
List<Person> sortedByAgePersons = new ArrayList<Person>(persons);
Collections.sort(sortedByAgePersons, new Comparator<Person>() {
public int compare(Person p1, Person p2) {
return Integer.valueOf(p1.getAge()).compareTo(p2.getAge());
}
});
Old Java style
Lambdaj
Lambdaj - Select
List<Sale> sales = select(sales, having(on(Sale.class).getBuyer(),
equalTo(selectMin(persons, on(Person.class).getAge()))));
Person youngest = null;
for (Person person : persons)
if (youngest == null || person.getAge() < youngest.getAge())
youngest = person;
List<Sale> buys = new ArrayList<Sale>();
for (Sale sale : sales)
if (sale.getBuyer().equals(youngest))
buys.add(sale);
Old Java style
Lambdaj
Lambdaj - Sum
Integer totalSumForStandaloneChannels =
sum(standaloneChannels,on(TvChannel.class).getPrice().getMonthlyFee());
Integer totalSumForStandaloneChannels = 0;
for (TvChannel channel: standaloneChannels) {
totalSumForStandaloneChannels += channel.getPrice.getMonthlyFee()
}
Old Java style
Lambdaj
Lambdaj - Group
Group<ChannelPackage> mutuallyExclusiveGroup =
group(selectedAddonPackages,
by(on(AddonChannelPackage.class).getGroup().getType()),
by(on(AddonChannelPackage.class).getGroup().getName()));
Don’t bother….
Old Java style
Lambdaj
Lambdaj - Index
Map<String, Car> carsByBrand = index(cars, on(Car.class).getBrand());
Map<String, Car> carsByBrand = new HashMap<String, Car>();
for (Car car : db.getCars())
carsByBrand.put(car.getBrand(), car);
Old Java style
Lambdaj
Lambdaj – Bulk Operations
List<Person> personInFamily = asList(new
Person(“Chuck"), new Person(“Lone Wolf"));
forEach(personInFamily).setLastName(“Norris");
Lambdaj - Closures
• Lambdaj Closures
Closure println = closure(); {
of(System.out).println(var(String.class));
}
//invoked by "closing" its free variable once:
println.apply("one");
//or more times:
println.each("one", "two", "three");

More Related Content

PDF
Agile Contracts by Drew Jemilo (Agile2015)
PPTX
BDD Short Introduction
PPTX
Agile Contracts
PDF
Blurring the Lines between ECM and CCMS
PDF
Full Service Ownership
PPTX
DDD eXchange
PDF
PagerDuty: Best Practices for On Call Teams
PPTX
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...
Agile Contracts by Drew Jemilo (Agile2015)
BDD Short Introduction
Agile Contracts
Blurring the Lines between ECM and CCMS
Full Service Ownership
DDD eXchange
PagerDuty: Best Practices for On Call Teams
Wednesday Webinar on "Strengthening your Agility with BDD - A demo using Cucu...

What's hot (10)

PPTX
A Guide To Offshore Development Center Set Up by Gramener Digital
PDF
Practiced agile developer with tdd & bdd
PDF
Job-to-be-done theory to practice : Ch4 Process
PDF
EDD Management Services Deck
PPTX
Behavior driven development (bdd)
PPTX
Minimum Viable Replacement: April 25, 2021
PPTX
Offshore development center (odc) setup up by faichi solutions - Case Study
PDF
FlexPod and Enterprise IT
PDF
How to successfully execute fixed price agile projects
A Guide To Offshore Development Center Set Up by Gramener Digital
Practiced agile developer with tdd & bdd
Job-to-be-done theory to practice : Ch4 Process
EDD Management Services Deck
Behavior driven development (bdd)
Minimum Viable Replacement: April 25, 2021
Offshore development center (odc) setup up by faichi solutions - Case Study
FlexPod and Enterprise IT
How to successfully execute fixed price agile projects
Ad

Similar to Behavior-driven Development and Lambdaj (20)

PPTX
Behaviour Driven Development (BDD) - Closing the Loop on a Great Fiori UX
PPTX
Topic tdd-and-bdd b4usolution
PDF
Inside Behavior Driven Development
PPTX
Agile Network India | Experiences in the Implementation of BDD / FDD | Supriy...
PDF
Agile Network India | Be Customer Centric with Test First Development | Mamat...
PDF
Agile Network India | Experiences in the Implementation of BDD / FDD | Supriy...
PPTX
Automation testing
PPTX
Behavior Driven Development
PPTX
BDD for APIs
PDF
bdd behaviour driven development
PPTX
Agile methodologies based on BDD and CI by Nikolai Shevchenko
PPTX
Bdd. Automate your requirements
PDF
German Testing Day 2015 - How behavior-driven development fuses developers an...
PDF
Is your API misbehaving?(Keith-Casey)
PPTX
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
PDF
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
PDF
Expo qa from user stories to automated acceptance tests with bdd
PDF
Whole team approach to agile testing bdd can help better pune 15th meetup
PPTX
Introduction to BDD
PDF
BDD in practice based on an open source project
Behaviour Driven Development (BDD) - Closing the Loop on a Great Fiori UX
Topic tdd-and-bdd b4usolution
Inside Behavior Driven Development
Agile Network India | Experiences in the Implementation of BDD / FDD | Supriy...
Agile Network India | Be Customer Centric with Test First Development | Mamat...
Agile Network India | Experiences in the Implementation of BDD / FDD | Supriy...
Automation testing
Behavior Driven Development
BDD for APIs
bdd behaviour driven development
Agile methodologies based on BDD and CI by Nikolai Shevchenko
Bdd. Automate your requirements
German Testing Day 2015 - How behavior-driven development fuses developers an...
Is your API misbehaving?(Keith-Casey)
Building In Quality: The Beauty Of Behavior Driven Development (BDD)
[ForumPHP 2023] Lights and shadows of BDD in Sylius (and probably other compa...
Expo qa from user stories to automated acceptance tests with bdd
Whole team approach to agile testing bdd can help better pune 15th meetup
Introduction to BDD
BDD in practice based on an open source project
Ad

More from Andreas Enbohm (8)

PPTX
Hybrid Applications
PPTX
Software Craftsmanship
PPT
SOLID Design Principles
PPTX
Java7 - Top 10 Features
PPTX
Java Extension Methods
PPT
PPT
Project Lambda - Closures after all?
Hybrid Applications
Software Craftsmanship
SOLID Design Principles
Java7 - Top 10 Features
Java Extension Methods
Project Lambda - Closures after all?

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
Teaching material agriculture food technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Understanding_Digital_Forensics_Presentation.pptx
MYSQL Presentation for SQL database connectivity
Reach Out and Touch Someone: Haptics and Empathic Computing
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
Understanding_Digital_Forensics_Presentation.pptx

Behavior-driven Development and Lambdaj

  • 1. BDD + Lambdaj Andreas Enbohm, Capgemini @enbohm
  • 2. BDD • Behavior-driven development (BDD) is an increasingly popular variation on test-driven development, which helps developers think more in terms of “executable specifications” than in terms of conventional tests
  • 3. Why use BDD? • Only build feature that add real value • Less wasted effort • Better communication • Higher quality, better tested product • Traceability
  • 4. BDD • BDD describes TDD done well - removes word ’test’ - replace it with behaviour, examples, scenarios etc. • Good habits; 1. Working outside-in 2. Using examples to clarify requirements (scenarios) 3. Using a common (ubiquitous) language
  • 5. BDD – Value Driven • A good goal should add value to business - increase revenue - reduce cost - avoid future cost - protect revenue ”Increase revenue by allowing customers to…” ”Prevent current customers switching to competing product by …”
  • 6. BDD – What Does the Customer Need? • Good teams push back! - users tend to express requirements as implementations - we need to find the business need! We need caching Why? So that the page loads fast So that the customer will buy stuff on our site and doesn’t leave page Why? Ok, so to increase the chance a customer will buy [stuff] it need to be ’fast’. Caching might be one way to achive this, but compressing images might be more effective. Or another way might be loaders, or ..
  • 7. BDD – Better understanding • Working outside-in - if you need to explain to a computer how to check the requirement, you’ll need to be damn sure understand it yourself • Business black-box testing is often done manually! - BDD enables automated acceptance testing • Mininum effort /code to fulfull requirement
  • 8. BDD – Common Language • Common Language - communication often the biggest overhead - even bigger if you allow different dialects of terminology - takes time but gains significant advantage
  • 9. BDD
  • 10. BDD
  • 11. BDD - Stories Story: Basic Purchase flow - User purchases a Grundpaket (id 21) Narrative: In order to attract new CDK customers As a leading channel reseller I want to provide an easy way to buy our products through our website Goal come first Stakeholder is secondary The feature must be required to achieve this goal
  • 12. BDD - Scenarios • The ’perfect’ bridge between the business- facing and technology-facing sides of a team Scenario: User selects a channel package for purchase (id 21.2) Given address search is done with address street Hantverkaregatan streetNo 28 and city Helsingborg on page url http://... When user select totalpaketet by clicking on choose button Then the user starts a purchase flow where the first step is called Grundpaket och box is shown Common language which is reflected all way down in the code
  • 13. BDD - Java • CDK use Jbehave - lots of documentation - uses Gherkin language
  • 15. BDD – CDK Implementation • No stories/scenarion from start - Emma wrote a lot of BDD stories - used by CDK as ’lightweight’ acceptance test • Selenium - browser automation • Spring as embedded runner - gives us DI • Page template patterns (see code)
  • 16. BDD – CDK Implementation • Pros - another way of thinking of test - sentence instead of test (even for our Junit tests) - we could make our major refactoring with confidence • Cons - selenium (engines) - issus/bugs with JBehave (fetching parameters, mapping to POJO) - we should not come up with the goal
  • 17. BDD • Reports show 75%* less bugs and 30%* faster to production
  • 18. Lambdaj • An internal DSL to manipulate collections without loops • Large part of business logic is always the same; iteration over collections of business objects to do a set of tasks • Loops (especially nested and mixed with conditions) are hard to read that to be written • for loop is inherently serial
  • 19. Lambdaj • Business logic should be less technical and closer to business fashion
  • 20. Lambdaj • Iterate over collections in order to: - select - aggregate - sort - filter - group - extract - and more..
  • 21. Lambdaj - Sort List<Person> sortedByAgePersons = sort(persons, on(Person.class).getAge()); List<Person> sortedByAgePersons = new ArrayList<Person>(persons); Collections.sort(sortedByAgePersons, new Comparator<Person>() { public int compare(Person p1, Person p2) { return Integer.valueOf(p1.getAge()).compareTo(p2.getAge()); } }); Old Java style Lambdaj
  • 22. Lambdaj - Select List<Sale> sales = select(sales, having(on(Sale.class).getBuyer(), equalTo(selectMin(persons, on(Person.class).getAge())))); Person youngest = null; for (Person person : persons) if (youngest == null || person.getAge() < youngest.getAge()) youngest = person; List<Sale> buys = new ArrayList<Sale>(); for (Sale sale : sales) if (sale.getBuyer().equals(youngest)) buys.add(sale); Old Java style Lambdaj
  • 23. Lambdaj - Sum Integer totalSumForStandaloneChannels = sum(standaloneChannels,on(TvChannel.class).getPrice().getMonthlyFee()); Integer totalSumForStandaloneChannels = 0; for (TvChannel channel: standaloneChannels) { totalSumForStandaloneChannels += channel.getPrice.getMonthlyFee() } Old Java style Lambdaj
  • 24. Lambdaj - Group Group<ChannelPackage> mutuallyExclusiveGroup = group(selectedAddonPackages, by(on(AddonChannelPackage.class).getGroup().getType()), by(on(AddonChannelPackage.class).getGroup().getName())); Don’t bother…. Old Java style Lambdaj
  • 25. Lambdaj - Index Map<String, Car> carsByBrand = index(cars, on(Car.class).getBrand()); Map<String, Car> carsByBrand = new HashMap<String, Car>(); for (Car car : db.getCars()) carsByBrand.put(car.getBrand(), car); Old Java style Lambdaj
  • 26. Lambdaj – Bulk Operations List<Person> personInFamily = asList(new Person(“Chuck"), new Person(“Lone Wolf")); forEach(personInFamily).setLastName(“Norris");
  • 27. Lambdaj - Closures • Lambdaj Closures Closure println = closure(); { of(System.out).println(var(String.class)); } //invoked by "closing" its free variable once: println.apply("one"); //or more times: println.each("one", "two", "three");