Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bringing BDD ideas to Pharo - Smalltalks 2011

Bringing BDD ideas to Pharo - Smalltalks 2011

Nahuel Garbezza

December 27, 2020
Tweet

More Decks by Nahuel Garbezza

Other Decks in Programming

Transcript

  1. Overview • What is Behaviour-driven development? • Specifications • Gherkin

    syntax • BDD Workflow • Demo • Conclusions & future work
  2. 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
  3. 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!
  4. 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
  5. 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
  6. 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 ;-)
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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 ;-)
  12. 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 ...
  13. 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
  14. 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
  15. 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!