View
167
Download
1
Category
Preview:
Citation preview
Trabajo de Inserción Profesional
Behaviour-Driven Development en Pharo Smalltalk
Nahuel Garbezza
Universidad Nacional de Quilmes
Tecnicatura en Programación InformáticaDepartamento de Ciencia y Tecnología
Director: Gabriela Arévalo, Ph.D.
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
¿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
¿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
GherkinLenguaje 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
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
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
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
Gherkin (V)Tipos de steps
● Contexto inicialGiven I am logged in as "test" user
● AccionesWhen I add a product to the cart
● Verificación de resultadosThen the table should be empty
11/30
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 hereend
Gherkin (VI)12/30
El ciclo de BDD1. 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
necesarios4. Implementar la lógica necesaria para que el
escenario funcione5. Refactorizar6. Comenzar de nuevo
13/30
BDD en Pharo Smalltalk14/30
● Tecnologías utilizadas
● Diseño
● Implementación
● Demostración
● Testing
TecnologíasDistribución de Smalltalkopen source
15/30
● Monticello● Metacello● SqueakSource
Herramientas Frameworks
● PetitParser● Mocketry
Parser
Sintaxis Gherkin aún no definida de manera formal
17/30
EspecificaciónGherkin tokens
AST(Abstract Syntax
Tree)
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
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
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
step definitionsImplementadas 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.
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
Testing26/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
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
Conclusiones
● Funcionalidad de Cucumber implementada
● Punto de partida para BDD en Smalltalk
● Proyecto open source ==> más feedback de
la comunidad
28/30
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
Recommended