Slide 1

Slide 1 text

Bringing BDD ideas to Pharo Nahuel Garbezza

Slide 2

Slide 2 text

Overview • What is Behaviour-driven development? • Specifications • Gherkin syntax • BDD Workflow • Demo • Conclusions & future work

Slide 3

Slide 3 text

What is Behaviour-Driven Development? BDD is about sharing the same vocabulary between all members of a project, using specifications Vocabulary SPECIFICATIONS Customers Developers Testers Analysts

Slide 4

Slide 4 text

What is Behaviour-Driven Development? Specifications should be Human-readable Executable and Cool! … 7 passed 0 failed ... Feature … In order to... I want to... Scenario... Do you understand? Yes! Of course!

Slide 5

Slide 5 text

Gherkin specifications syntax Used by ...and more

Slide 6

Slide 6 text

Specifications syntax Feature: Serve coffee In order to avoid falling asleep As a customer I want to buy a coffee Scenario: Buy last coffee Given there is 1 coffee left in the machine And I have paid 1$ When I press the coffee button Then I should have a coffee served

Slide 7

Slide 7 text

Specifications syntax Feature: Serve coffee In order to avoid falling asleep As a customer I want to buy a coffee Scenario: Buy last coffee Given there is 1 coffee left in the machine And I have paid 1$ When I press the coffee button Then I should have a coffee served Feature

Slide 8

Slide 8 text

Specifications syntax Feature: Serve coffee In order to avoid falling asleep As a customer I want to buy a coffee Scenario: Buy last coffee Given there is 1 coffee left in the machine And I have paid 1$ When I press the coffee button Then I should have a coffee served Narrative Good practice ;-)

Slide 9

Slide 9 text

Specifications syntax Feature: Serve coffee In order to avoid falling asleep As a customer I want to buy a coffee Scenario: Buy last coffee Given there is 1 coffee left in the machine And I have paid 1$ When I press the coffee button Then I should have a coffee served Scenario

Slide 10

Slide 10 text

Specifications syntax Scenario: Buy last coffee Given there is 1 coffee left in the machine And I have paid 1$ When I press the coffee button Then I should have a coffee served Steps Initial context Actions Expected outcomes

Slide 11

Slide 11 text

Step definitions How the computer knows what means Given there is 1 coffee left in the machine ? How can it be executed if it's a simple string? There's no magic :-( It's your work as a developer to give it a meaning... ... by writing step definitions

Slide 12

Slide 12 text

Step definitions examples Given /there is|are (\d*) coffees? left in the machine/ do |n| @machine = CofeeMachine.new(n.to_i) end @Given("there is|are (\d*) coffees? left in the machine") public void givenThereAreNCoffeesLeft(String n) { this.machine = new CofeeMachine(Integer.parseInt(n)); } Regular expressions Parameters

Slide 13

Slide 13 text

The BDD Workflow Write specification of a scenario Watch it fail Write code to make the scenario pass Refactor! Do TDD cycles here if necessary ;-)

Slide 14

Slide 14 text

Demo

Slide 15

Slide 15 text

A little of self-testing Cucumber people have written many features to bootstrap any implementation. Example: ... Scenario: All steps passing means the scenario passes Given a scenario "Basic Arithmetic" with: """ When I add 4 and 5 Then the result is 9 """ And the step "I add 4 and 5" has a passing mapping And the step "the result is 9" has a passing mapping When Cucumber executes the scenario "Basic Arithmetic" Then the scenario passes ...

Slide 16

Slide 16 text

There's a lot of work to do... • Stable release • Step definitions to support Seaside, Magma and other frameworks, to do *real* BDD • Cool features in Cucumber such as: o Automatic generation of step definition templates o Reporting (PDF, HTML, etc) • Integration (Browser, CI, etc) • Write translations for Gherkin (Cucumber has ~ 40) • Write documentation o Wiki, tutorials o PBE chapter

Slide 17

Slide 17 text

Questions? Scenario: No questions Given everything (or nothing :P) was understood When I ask for questions Then no one raises his/her hand And I can go on Scenario: Questions! Given someone curious When I ask for questions Then someone asks me something And I try to answer

Slide 18

Slide 18 text

Interested? http://squeaksource.com/Kiwi http://github.com/ngarbezza/kiwi-pharo

Slide 19

Slide 19 text

The end Scenario: Finishing the talk! Given we're done When I arrived to this slide Then I thank you for listening And we can go to the coffee break!