bdd & cucumber

Post on 05-Dec-2014

668 Views

Category:

Technology

13 Downloads

Preview:

Click to see full reader

DESCRIPTION

Introducción a BDD usando Cucumber.

TRANSCRIPT

BDD & Dos amigos inseparables

@EnriqueSanchezB www.enrique-sanchez.me

¿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

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

¿Quién es este pesao?

¿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?

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"

¡¡¡ESO NO ES AGILE!!!

Waterfall

Coste de un cambio

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."

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

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.

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

Behaviour Drive-Development

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

Behaviour Drive-Development

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

• 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

¿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

Gherkin

• Business Readable

• Describe el comportamiento del software sin importar el desarrollo

• Documentación

Gherkin: Sintaxis

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

Cucumber• Framework BDD

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

http://cukes.info/

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

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

Cucumber: ¿Cómo funciona?

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

El entorno

• Configurar todo esto es un engorro

¡Y NOSOTROS NO ESTAMOS AQUÍ PARA ESTO!

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

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

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

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

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

Cucumber: Primeros Pasos

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

Cucumber: Primeros Pasos

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

• Ejecutemos de nuevo

Cucumber: Primeros Pasos

¡¡¡ESO NO VALE PARA NADA!!!

QUIERO ALGO DE VERDAD

Browsing Tests

• Probemos una web real…

!

<spam>  Usemos </spam>

Pero… ¿esto se usa de verdad?

Veamos indeed…

y careers 2.0…

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

Entonces…

Aprende BDD que lo vas a necesitar

¿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

¿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>

Rompe algo y no tengas miedo a

equivocarte

¿Por dónde empiezo?

Graciashola@enrique-sanchez.me

!enrique.sanchezbayuela@medianet.es

!@EnriqueSanchezB

top related