tests de aceptación con cucumber
DESCRIPTION
Breve introducción a las características más importantes de CucumberTRANSCRIPT
Tests de aceptación con
Tests de aceptación
• La idea viene de eXtreme Programming (XP)
• Se llaman tests de aceptación porque expresan lo que el software tiene que hacer para que los stakeholders lo consideren “aceptable”
• Por lo tanto desarrolladores y stakeholders son los que escriben las pruebas
Tests de aceptación
• Los tests unitarios nos dicen que lo que estamos desarrollando está correcto
• Los tests de aceptación nos dicen que lo que estamos desarrollando es lo correcto
Tests de aceptación
• Aumenta el feedback se reducen los malentendidos
• Surge un lenguaje común que todos los relacionados con el proyecto entienden
• Al ser escritos como ejemplos estimula la imaginación de los participantes
Cucumber
• Cucumber hace fácil leer y escribir tests de aceptación por cualquier miembro del equipo
• Cucumber se convierte en una herramienta que fomenta la colaboración y la comunicación
• Escribir tests de aceptación con Cucumber no son sólo tests, son especificaciones ejecutables
Cucumber
• Los tests de Cucumber pueden ser escritos y leídos por los stakeholders, como en un documento de requisitos
• Los tests de Cucumber pueden ser ejecutados por una máquina y ver su nivel de cumplimiento
• La documentación se mantiene actualizada y refleja el estado del proyecto
• Gherkin es el lenguaje que usa Cucumber para escribir las especificaciones
Feature: Sign upSign up should be quick and friendly.
Scenario: Successful sign upNew users should get a confirmation email and be
greeted personally by the site once signed in.
Given I have chosen to sign upWhen I sign up with valid detailsThen I should receive a confirmation emailAnd I should see a personalized greeting message
Scenario: Duplicate emailWhere someone tries to create an account for an email address that already exists.
Given I have chosen to sign upBut I enter an email address that has already
registeredThen I should be told that the email is already
registeredAnd I should be offered the option to recover my
password
Cucumber
• Podemos indicar que varios escenarios compartan un mismo background
Feature: Change PINAs soon as the bank issues new cards to customers, they aresupplied with a Personal Identification Number (PIN) thatis randomly generated by the system.
In order to be able to change it to something they can easilyremember, customers with new bank cards need to be able tochange their PIN using the ATM.Background:
Given I have been issued a new cardAnd I insert the card, entering the correct PINAnd I choose "Change PIN" from the menu
Scenario: Change PIN successfullyWhen I change the PIN to 9876Then the system should remember my PIN is now 9876
Scenario: Try to change PIN to the same as beforeWhen I try to change the PIN to the original PIN
numberThen I should see a warning messageAnd the system should not have changed my PIN
Cucumber
• Podemos indicar los datos que se usan en un escenario en forma de tabla
Given a User "Michael Jackson" born on August 29, 1958And a User "Elvis" born on January 8, 1935And a User "John Lennon" born on October 9, 1940
Given these Users:| name | date of birth || Michael Jackson | August 29, 1958 || Elvis | January 8, 1935 || John Lennon | October 9, 1940 |
Cucumber• Podemos ejecutar un mismo escenario con varios valores de
entrada y de salida
Scenario Outline: Withdraw fixed amountGiven I have <Balance> in my accountWhen I choose to withdraw the fixed amount of <Withdrawal>Then I should <Outcome>And the balance of my account should be <Remaining>Examples: Successful withdrawal
| Balance | Withdrawal | Outcome | Remaining || $500 | $50 | receive $50 cash | $450 || $500 | $100 | receive $100 cash | $400 |
Examples: Attempt to withdraw too much| Balance | Withdrawal | Outcome | Remaining
|| $100 | $200 | see an error message | $100
|| $0 | $50 | see an error message | $0
|
Cucumber
• Podemos anotar los escenarios para ejecutar sólo los que nos interesen
@slow @widgets @nightlyScenario: Generate overnight report
Given I am logged inAnd there is a report "Total widget sales history"
Enlaces de interés
• http://cukes.info/• https://github.com/
cucumber/cucumber/wiki
• http://pragprog.com/book/hwcuc/the-cucumber-book
• http://pragprog.com/book/dhwcr/cucumber-recipes
Contacto
• https://github.com/tmoreno/tutorialcucumber
• @tmorenobernal