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

BDD & Cucumber

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

BDD & Cucumber

Una pequeña introducción sobre BDD y Cucumber

Avatar for Enrique Sánchez

Enrique Sánchez

March 24, 2014

More Decks by Enrique Sánchez

Other Decks in Programming

Transcript

  1. ¿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
  2. • Actualmente echo una mano montando entornos y diseñando la

    estrategia de testing automático en ¿Quién es este pesao?
  3. ¿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?
  4. 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"
  5. Agile Manifesto The 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."
  6. Agile Manifesto The 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
  7. Specification By Defect Specification 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.
  8. Specification By Defect Specification 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
  9. • 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
  10. ¿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
  11. Cucumber • Framework BDD • Escrito en Ruby pero disponible

    para Java (Cucumber- JVM), Python (Lettuce), Javascript (cucumber-js)… http://cukes.info/
  12. 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
  13. 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
  14. El entorno • Configurar todo esto es un engorro ¡Y

    NOSOTROS NO ESTAMOS AQUÍ PARA ESTO!
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. • Arreglemos el test editando el fichero first.rb y creando

    una clase Calculator que permita realizar operaciones. • Ejecutemos de nuevo Cucumber: Primeros Pasos
  21. 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
  22. ¿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
  23. ¿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>