bdd & cucumber

47
BDD & Dos amigos inseparables @EnriqueSanchezB www.enrique-sanchez.me

Upload: enrique-sanchez

Post on 05-Dec-2014

668 views

Category:

Technology


13 download

DESCRIPTION

Introducción a BDD usando Cucumber.

TRANSCRIPT

Page 1: BDD & Cucumber

BDD & Dos amigos inseparables

@EnriqueSanchezB www.enrique-sanchez.me

Page 2: BDD & Cucumber

¿Quién es este pesao?• Technical Team Leader y Responsable Técnico del Área de

Testing en !!!• Más de 3 años de experiencia en testing en empresas

como !!

!• Evangelista BDD y Agile

Page 3: BDD & Cucumber

• Actualmente echo una mano montando entornos y diseñando la estrategia de testing automático en

¿Quién es este pesao?

Page 4: BDD & Cucumber

¿De qué va a ir esta charla?

• ¿Qué es eso de BDD, TDD, ATDD y todas esas siglas raras?

• ¿Qué tiene de especial el BDD? ¿Es otra moda más?

• ¿Cucumber? ¿En serio?

Page 5: BDD & Cucumber

Un poco de historia

Debugging oriented

Demonstration oriented

Destruction oriented

Evaluation oriented

Prevention oriented

1957 1978 1982 1988

Fuente: Gelperin, D.; B. Hetzel. "The Growth of Software Testing"

Page 6: BDD & Cucumber

¡¡¡ESO NO ES AGILE!!!

Page 7: BDD & Cucumber

Waterfall

Page 8: BDD & Cucumber

Coste de un cambio

Page 9: BDD & Cucumber

Agile ManifestoThe style here is to write a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run. […] Now, instead of just coding on, we want to get immediate feedback and practice "code a little, test a little, code a little, test a little."

Page 10: BDD & Cucumber

Agile ManifestoThe style here is to write a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run. […] Now, instead of just coding on, we want to get immediate feedback and practice "code a little, test a little, code a little, test a little."

TDD

Page 11: BDD & Cucumber

Specification By DefectSpecification By Example isn't the way most of us have been brought up to think of specifications. Specifications are supposed to be general, to cover all cases. Examples only highlight a few points, you have to infer the generalizations yourself. This does mean that Specification By Example can't be the only requirements technique you use, but it doesn't mean that it can't take a leading role.

Page 12: BDD & Cucumber

Specification By DefectSpecification By Example isn't the way most of us have been brought up to think of specifications. Specifications are supposed to be general, to cover all cases. Examples only highlight a few points, you have to infer the generalizations yourself. This does mean that Specification By Example can't be the only requirements technique you use, but it doesn't mean that it can't take a leading role.

ATDD

Page 13: BDD & Cucumber

Behaviour Drive-Development

“Behaviour” is a more useful word than “test”

Page 14: BDD & Cucumber

Behaviour Drive-Development

“Behaviour” is a more useful word than “test”BDD

Page 15: BDD & Cucumber
Page 16: BDD & Cucumber

• BDD se centra en el comportamiento mientras que TDD se centra en la implementación

• ATDD se centra en capturar requisitos en test de aceptación y los usa para conducir el desarrollo

• ATDD está centrado en los requisitos desde el punto de vista del desarrollador, BDD está enfocado en la captura de requisitos desde el cliente

Page 17: BDD & Cucumber
Page 18: BDD & Cucumber

¿Qué es BDD?• Método de diseño y codificación que integra

pruebas.

Aceptación Unitarias

• Orienta a un desarrollo “Outside -> In”

• Define el uso de un DSL para pruebas

Un subconjunto del lenguaje natural —> Gherkin

Page 19: BDD & Cucumber

Gherkin

• Business Readable

• Describe el comportamiento del software sin importar el desarrollo

• Documentación

Page 20: BDD & Cucumber

Gherkin: Sintaxis

https://github.com/cucumber/cucumber/wiki/Gherkin

Page 21: BDD & Cucumber

Cucumber• Framework BDD

• Escrito en Ruby pero disponible para Java (Cucumber-JVM), Python (Lettuce), Javascript (cucumber-js)…

http://cukes.info/

Page 22: BDD & Cucumber

Cucumber: ¡¡Lo quiero!!1. Instala Ruby* !\curl  -­‐sSL  https://get.rvm.io  |  bash  -­‐s  stable  

!

2. Instala Cucumber !sudo  gem  install  cucumber

* Instala: última versión de Ruby + RVM (Ruby version manager) + RubyGems

Page 23: BDD & Cucumber

Cucumber: ¿Cómo funciona?

• Es una herramienta de línea de comandos

• Lee los ficheros .features del directorio indicado

• Por cada uno de los scenarios ejecuta los steps

Page 24: BDD & Cucumber

Cucumber: ¿Cómo funciona?

Page 25: BDD & Cucumber

¡¡¡Quiero ver un ejemplo que no me gusta la magia!!!!

Page 26: BDD & Cucumber

El entorno

• Configurar todo esto es un engorro

¡Y NOSOTROS NO ESTAMOS AQUÍ PARA ESTO!

Page 27: BDD & Cucumber

El entorno• Usemos Vagrant (http://www.vagrantup.com/)

• Bájate la última versión de VirtualBox (https://www.virtualbox.org/)

• Instala Vagrant (http://www.vagrantup.com/downloads.html)

• Instala Git (http://git-scm.com/)

• Clona este proyecto

git  clone  https://github.com/enriquesanchezb/vagrant-­‐cucumber-­‐watir.git  

• Arranca vagrant

vagrant  up  

vagrant  ssh

Page 28: BDD & Cucumber

El entorno¡¡¡ Y ya lo tienes montado madafaca !!!

Page 29: BDD & Cucumber

Cucumber: Primeros Pasos• Crea un directorio: kit-­‐cucumber  

• Crea un subdirectorio features

• Crea un archivo: features/first_steps.features

• En la consola sitúate en el directorio y escribe: cucumber

Page 30: BDD & Cucumber

Cucumber: Primeros Pasos

• Crear un test es simple: abre un editor de texto y escribe

Feature:  Division      In  order  to  avoid  silly  mistakes      Cashiers  must  be  able  to  calculate  a  fraction  !    Scenario:  Regular  numbers          Given  I  have  entered  3  into  the  calculator          And  I  have  entered  2  into  the  calculator          When  I  press  divide          Then  the  result  should  be  1.5  on  the  screen

• Ahora ejecuta:>  cucumber  features/first_steps.features

Page 31: BDD & Cucumber

Cucumber: Primeros Pasos

• Crear un test es simple: abre un editor de texto y escribe

Feature:  Division      In  order  to  avoid  silly  mistakes      Cashiers  must  be  able  to  calculate  a  fraction  !    Scenario:  Regular  numbers          Given  I  have  entered  3  into  the  calculator          And  I  have  entered  2  into  the  calculator          When  I  press  divide          Then  the  result  should  be  1.5  on  the  screen

• Ahora ejecuta:>  cucumber  features/first_steps.features

wow so easy

much minimalist

so hipster

Page 32: BDD & Cucumber

Cucumber: Primeros Pasos

Page 33: BDD & Cucumber

Cucumber: Primeros Pasos

• Crea un directorio dentro del directorio features llamado step_definitions  

• Copia la salida obtenida de la ejecución del test y cópiala a un nuevo fichero llamado features/step_definitions/first.rb

• Ejecuta el test de nuevo

Page 34: BDD & Cucumber

Cucumber: Primeros Pasos

Page 35: BDD & Cucumber

• Arreglemos el test editando el fichero first.rb y creando una clase Calculator que permita realizar operaciones.

• Ejecutemos de nuevo

Cucumber: Primeros Pasos

Page 36: BDD & Cucumber

¡¡¡ESO NO VALE PARA NADA!!!

QUIERO ALGO DE VERDAD

Page 37: BDD & Cucumber

Browsing Tests

• Probemos una web real…

!

<spam>  Usemos </spam>

Page 38: BDD & Cucumber
Page 39: BDD & Cucumber

Pero… ¿esto se usa de verdad?

Page 40: BDD & Cucumber

Veamos indeed…

Page 41: BDD & Cucumber

y careers 2.0…

Page 42: BDD & Cucumber

Entonces…

• El testing no es sólo probar cosas a mano si no que debe de formar parte de la cultura de la organización

• BDD y Cucumber son muy demandados por la industria ya que permite introducir testing desde el principio del desarrollo

Page 43: BDD & Cucumber

Entonces…

Aprende BDD que lo vas a necesitar

Page 44: BDD & Cucumber

¿Por dónde empiezo?

• Cucumber Website: http://cukes.info/

• Asiste a alguna de las charlas gratuitas que da MADQA http://www.meetup.com/MADQA-Grupo-Meetup-de-QA-y-TESTING-de-SOFTWARE-en-Madrid/

• Lee y practica: https://github.com/cucumber/cucumber/wiki/tutorials-and-related-blog-posts

Page 45: BDD & Cucumber

¿Por dónde empiezo?

<spam id=“1”> Busco un becario para montar un entorno de Integración Continua en el FRAV </spam>

!<spam id=“2”> ¡En Medianet estamos contratando! </spam>

Page 46: BDD & Cucumber

Rompe algo y no tengas miedo a

equivocarte

¿Por dónde empiezo?