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

Behaviour-Driven Development en Pharo Smalltalk - Trabajo de Inserción Profesional UNQ

Behaviour-Driven Development en Pharo Smalltalk - Trabajo de Inserción Profesional UNQ

UNQ - Tecnicatura en Programación Informática - Trabajo de Inserción Profesional.

Dirigido por Gabriela Arévalo. Presentado el 4/5/2012.

Nahuel Garbezza

December 27, 2020
Tweet

More Decks by Nahuel Garbezza

Other Decks in Programming

Transcript

  1. Trabajo de Inserción Profesional Behaviour-Driven Development en Pharo Smalltalk Nahuel

    Garbezza Universidad Nacional de Quilmes Tecnicatura en Programación Informática Departamento de Ciencia y Tecnología Director: Gabriela Arévalo, Ph.D.
  2. Contenidos • Introducción ◦ ¿Qué es BDD? Principios y herramientas

    ◦ Especificaciones Gherkin, sintaxis y funcionamiento ◦ El ciclo de BDD • BDD en Pharo Smalltalk ◦ Diseño ◦ Implementación ◦ Demostración ◦ Testing • Conclusiones 2/30
  3. ¿Qué es BDD? • 2006: Dan North publica Introducing BDD

    • Especificaciones deben ser: ◦ de fácil lectura ◦ ejecutables • Especificaciones, luego código • Problema: Falta de marco teórico 4/30
  4. ¿Qué es BDD? (II) Principios • It's all behaviour •

    Deliver stakeholder value • Enough is enough Otras características • Adhiere al manifiesto ágil • Ayuda a construir un lenguaje en común (Domain-Driven Design, Eric Evans) • Propone desarrollo outside-in 5/30
  5. Gherkin Lenguaje para escribir las especificaciones • No es un

    lenguaje de programación • Fácil de leer • Ejecutable (con código asociado) • Levemente estructurado • Internacionalizable 7/30
  6. Gherkin (II) Feature: Serve coffee In order to earn money

    Customers should be able to buy coffee at all times Scenario: Buy last coffee Given there are 1 coffee left in the machine And I have deposited 1 dollar When I press the coffee button Then I should be served a coffee Feature 8/30
  7. Gherkin (III) Scenario Feature: Serve coffee In order to earn

    money Customers should be able to buy coffee at all times Scenario: Buy last coffee Given there are 1 coffee left in the machine And I have deposited 1 dollar When I press the coffee button Then I should be served a coffee 9/30
  8. Gherkin (IV) Steps Feature: Serve coffee In order to earn

    money Customers should be able to buy coffee at all times Scenario: Buy last coffee Given there are 1 coffee left in the machine And I have deposited 1 dollar When I press the coffee button Then I should be served a coffee 10/30
  9. Gherkin (V) Tipos de steps • Contexto inicial Given I

    am logged in as "test" user • Acciones When I add a product to the cart • Verificación de resultados Then the table should be empty 11/30
  10. Parámetro La especificación por sí sola no se ejecuta, necesita

    de código que "responda" a ella. step definition: código asociado a un step Ejemplo (Cucumber): Given /^there are (\d+) coffees left$/ do |coffees| # Some Ruby code here end Gherkin (VI) 12/30
  11. El ciclo de BDD 1. Especificar un nuevo escenario (que

    generará valor para el usuario) 2. Ejecutar el escenario (no debería pasar) 3. Implementar los steps definitions que sean necesarios 4. Implementar la lógica necesaria para que el escenario funcione 5. Refactorizar 6. Comenzar de nuevo 13/30
  12. BDD en Pharo Smalltalk 14/30 • Tecnologías utilizadas • Diseño

    • Implementación • Demostración • Testing
  13. Tecnologías Distribución de Smalltalk open source 15/30 • Monticello •

    Metacello • SqueakSource Herramientas Frameworks • PetitParser • Mocketry
  14. Parser Sintaxis Gherkin aún no definida de manera formal 17/30

    Especificación Gherkin tokens AST (Abstract Syntax Tree)
  15. Parser (II) scenario ^self comment , self tagGroup trim ,

    self scenarioKeyword , #blank asParser star , self untilEndOfLine , self untilKeyword trim , self steps 18/30 scenario ^super scenario ==> [:tokens| ScenarioASTNode new comment: tokens first; tagGroup: tokens second; title: tokens fifth; description: tokens sixth trimBoth; steps: tokens seventh ] Ejemplo
  16. runner (interfaz) Responsable de armar configuraciones de ejecución: • features

    ◦ desde archivos de texto ◦ desde métodos en la imagen de Pharo • clases con steps definitions • filtro por tags Retorna resultados en cada ejecución 19/30
  17. runner (implementación) • Recorre el AST ◦ Feature -> ejecutar

    scenarios ◦ Scenario -> ejecutar steps ◦ Step -> buscar step definitions y ejecutarlas • Genera resultados • Implementado como visitor 20/30
  18. step definitions Implementadas como métodos anotados con diferentes pragmas. Ejemplo:

    21/30 Parámetro AnyClass >> givenThereAreNCoffeesLeft: qty <given: 'there are (\d+) coffees left'> machine := CoffeeMachine new. machine stock: qty.
  19. Resultados • Contienen información de una ejecución • Posibles estados

    de un step: ◦ undefined ◦ passed ◦ failed ◦ pending ◦ skipped • Información adicional ◦ Método con step definition encontrado ◦ Error ocurrido 22/30
  20. Testing 26/30 • Tests unitarios (SUnit) ◦ 130 Tests OK

    ◦ 73% cobertura s0 sobre Core • Tests de aceptación ◦ auto-test ◦ Cucumber Technology Kit ◦ Feature 'core' actualmente OK
  21. Extra • Más elementos de Gherkin ◦ Background ◦ Scenario

    Outline ◦ Tablas y Strings ◦ Tags • Perfiles de ejecución ◦ API declarativa ◦ Asocia nombre y configuración • Formatter 27/30
  22. Conclusiones • Funcionalidad de Cucumber implementada • Punto de partida

    para BDD en Smalltalk • Proyecto open source ==> más feedback de la comunidad 28/30
  23. Trabajos Futuros • Integración ◦ Frameworks (ej: Seaside) ◦ Herramientas

    de desarrollo (browser, integración continua) • Interfaz gráfica utilizando Glamour • Generación de step definitions • Reportes • Gherkin ◦ definir formalmente la gramática ◦ incorporar traducciones 29/30