Sunteți pe pagina 1din 47

BDD &

Dos amigos inseparables


@EnriqueSanchezB
www.enrique-sanchez.me

Quin es este pesao?

Technical Team Leader y Responsable Tcnico del rea de


Testing en

!
!
!

Ms de 3 aos de experiencia en testing en empresas


como

!
!
!

Evangelista BDD y Agile

Quin es este pesao?

Actualmente echo una mano montando entornos y


diseando la estrategia de testing automtico en

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

Cucumber? En serio?

Un poco de historia
1957

Debugging
oriented

Demonstration
oriented

1978

Destruction
oriented

1982

Evaluation
oriented

1988

Prevention oriented

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

ESO NO ES AGILE!!!

Waterfall

Coste de un cambio

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

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

D
D
T

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

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

D
D
T
A

Behaviour Drive-Development

Behaviour is a more useful word


than test

Behaviour Drive-Development

D
D
B

Behaviour is a more useful word


than test

BDD se centra en el comportamiento mientras que


TDD se centra en la implementacin

ATDD se centra en capturar requisitos en test de


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

Mtodo de diseo y codificacin que integra


pruebas.
Aceptacin
Unitarias

Outside -> In

Orienta a un desarrollo

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

Documentacin

Gherkin: Sintaxis

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

Cucumber

Framework BDD

Escrito en Ruby pero disponible para Java (CucumberJVM), 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 versin de Ruby + RVM (Ruby version manager) + RubyGems

Cucumber: Cmo funciona?

Es una herramienta de lnea de comandos

Lee los ficheros .features del directorio indicado

Por cada uno de los scenarios ejecuta los steps

Cucumber: Cmo 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/)

Bjate la ltima versin 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:

Crea un subdirectorio

Crea un archivo: features/first_steps.features

En la consola sitate en el directorio y escribe:

kit-cucumber
features

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:

wow so easy

> cucumber features/first_steps.features

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 ejecucin del test y


cpiala a un nuevo fichero llamado features/
step_definitions/first.rb

Ejecuta el test de nuevo

Cucumber: Primeros Pasos

Cucumber: Primeros Pasos

Arreglemos el test editando el fichero first.rb y


creando una clase Calculator que permita realizar
operaciones.

Ejecutemos de nuevo

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 slo probar cosas a mano si no que


debe de formar parte de la cultura de la
organizacin

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 dnde empiezo?

Cucumber Website: http://cukes.info/

Asiste a alguna de las charlas gratuitas que da


MADQA http://www.meetup.com/MADQA-GrupoMeetup-de-QA-y-TESTING-de-SOFTWARE-en-Madrid/

Lee y practica: https://github.com/cucumber/


cucumber/wiki/tutorials-and-related-blog-posts

Por dnde empiezo?


<spam id=1> Busco un becario para montar un entorno de
Integracin Continua en el FRAV </spam>
!

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

Por dnde empiezo?


Rompe algo y no
tengas miedo a
equivocarte

Gracias
hola@enrique-sanchez.me
!

enrique.sanchezbayuela@medianet.es
!

@EnriqueSanchezB

S-ar putea să vă placă și