Share
Embed
Bringing BDD ideas to Pharo - Smalltalks 2011
Presentation recorded at: https://www.youtube.com/watch?v=m2t_MbVAdis
Nahuel Garbezza
December 27, 2020
Transcript
19 slides
-
Overview • What is Behaviour-driven development? • Specifications • Gherkin
syntax • BDD Workflow • Demo • Conclusions & future work -
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 -
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! -
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 -
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 -
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 ;-) -
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 -
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 -
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 -
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 -
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 ;-) -
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 ... -
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 -
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 -
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!