Cucumber-QA_Night

30
http://cukes.info/ Taíse Dias da Silva [email protected]

Transcript of Cucumber-QA_Night

Page 1: Cucumber-QA_Night

http://cukes.info/

Taíse Dias da [email protected]

Page 2: Cucumber-QA_Night

Agenda

o Por que Cucumber?o Estrutura do Cucumber (testing stack)o Feature, Scenario & Step Definitionso Melhores práticaso Referências

Page 3: Cucumber-QA_Night

Por que Cucumber?

Page 4: Cucumber-QA_Night

Software - Problemas

o Software: o que pode acontecer de errado?o Defeito de implementação

o Programa não faz o que pretendiao Corrigido em desenvolvimento/QA

o Defeito no requisitoo Programa faz o que pretendiao O requisito não foi compreendido corretamente

Page 5: Cucumber-QA_Night

Software - Problemas

o 50-60% dos problemas encontrados por testadores são causados por problemas nos requisitos

o 100-200% mais caro para se corrigir do que os outros defeitos porque o código já estará escrito

Page 6: Cucumber-QA_Night

Como Cucumber pode ajudar?

o Cucumber é uma ferramenta baseada em Behavior Driven Development (BDD)

o Stakeholders focam em especificação baseada no valor do negócio

o Especificações escritas em linguagem natural (qualquer um consegue ler)

Page 7: Cucumber-QA_Night

o Especificações viram testes de aceitação, descrevendo exemplos do comportamento do software antes da implementação (feedback cedo)

o Testes são usados na regressão durante a evolução do software

Como Cucumber pode ajudar?

Page 8: Cucumber-QA_Night

O que é Cucumber?

o Cucumber é uma ferramenta que executa descrições funcionais em

texto puro como testes automatizadoso Texto puro: escrito em Gherkino Automação: escrita em alguma

linguagem de programação

Page 9: Cucumber-QA_Night

Cucumber Testing Stack

Page 10: Cucumber-QA_Night

Cucumber testing stack

BusinessFacing

Seu projeto

Features

Scenarios

Steps Step definitions

Support code

Automation library

Seu sistema

TechnologyFacing

Page 11: Cucumber-QA_Night

Cucumber testing stack

BusinessFacing

Seu projeto

Features

Scenarios

Steps Step definitions

Support code

Automation library

Seu sistema

TechnologyFacing

Web Application

Web Service

Android

Selenium Watir

Page 12: Cucumber-QA_Night

Features, Scenarios &Step Definitions

Page 13: Cucumber-QA_Night

Feature

o Testes em Cucumber são agrupados em features

Feature: Acess app Dinossaurs <<description>>

o Cada teste em Cucumber chama-se scenario

Scenario: List dinos names

Page 14: Cucumber-QA_Night

Scenario & Steps

o Cada scenario contém steps que diz ao Cucumber o que fazer

Given I am in Dino app When I choose List Then I see the list of dinosaurs

Page 15: Cucumber-QA_Night

Step Definitions

o Para que Cucumber saiba como executar um scenario de uma feature, precisamos escrever step definition.

Given(/^I am in Dino app$/) do pending # express the regexp above with the code you wish you had end

Page 16: Cucumber-QA_Night

Step Definitionso Para implementar step definition:o Substitua comentário por código o Código delega para o support code,

específico do domínio da sua appo O support code usa uma automation library

para interagir com o sistema.

Given(/^I am in Dino app$/) do @page = Index.new @page.load end

Page 17: Cucumber-QA_Night

Step Definitions

When(/^I choose List$/) do @page.list_link.clickend

Then(/^I see the list of dinosaurs$/) do @page.should have_dino_list @page.should_not have_dino_imageend

Page 18: Cucumber-QA_Night

Exemplo

o Cucumber JVM:o https://github.com/taisedias/dinossauros

Page 19: Cucumber-QA_Night

Melhores Práticas

Page 20: Cucumber-QA_Night

Features Declarativas

Feature: Dinosaurs app accessScenario: List dinos names Given I go to the home page When I click the link "List" Then the page should contain a list of Dinosaurs

Feature: Dinosaurs app accessScenario: List dinos names Given I am in Dino app When I list dinos names Then I see a list of Dinosaurs

Page 21: Cucumber-QA_Night

Features Narrativas

Feature: Dinosaurs app accessScenario: List dinos names Given I am in Dino app When I choose List Then I see list of Dinosaurs

Feature: Dinosaurs app accessIn order to identify dinosaursAs a bones keeperI want to access information about dinosaursScenario: List dinos names Given I am in Dino app When I choose List Then I see list of Dinosaurs

Page 22: Cucumber-QA_Night

Evitar steps conjuntivos# Scenario 1...When I compose an email to “[email protected]” and send it...

# step definitionWhen(/^I compose an email to “(.*)” and send it$/) do |email_address| email = Email.new recipient: email_address email.sendend

# Scenario 2...When I compose an email to “[email protected]”And I add “[email protected]” as recipient And I send the email...# step definitionWhen(/^I compose an email to “(.*)”$/) do |email_address| @email = Email.new recipient: email_addressendWhen(/^I send an email$/) do @email.sendend

Page 23: Cucumber-QA_Night

Reusar step definitions

# feature...When I compose an informal email to “[email protected]” And I send an email...# step definitionWhen(/^I compose an email to “(.*)” and send it$/) do |email_address| @email = Email.new recipient: email_addressend...When(/^I compose an informal email to “(.*)”$/) do |email_address| Step %{I compose an e-mail to “#{email_address}”} @email.set_greeting “Ahoi mate”end

Page 24: Cucumber-QA_Night

Não abusar do uso do BackgroundFeature: Using the background In order to ... Background: Given I am signed up as “[email protected]” Scenario: Acessing a build When I go to the dashboard Then I should be able to access the build

Scenario: Restarting a build When I go to the dashboard Then I should be able to restart the build

Page 25: Cucumber-QA_Night

Feature: Using the background In order to ... Background: Given I am signed up as “[email protected]” When I go to the dashboard Scenario: Acessing a build Then I should be able to access the build

Scenario: Restarting a build Then I should be able to restart the build

Não abusar do uso do Background

Page 26: Cucumber-QA_Night

Resumo

Page 27: Cucumber-QA_Night

Resumo

o Cucumber ajuda o time de desenvolvimento de software a:o Compreender corretamente os requisitos

através de exemploso Usar o mesmo vocabulário para fala sobre

o softwareo Ter uma documentação viva (executável) e

de fácil leitura em linguagem natural

Page 28: Cucumber-QA_Night

Resumo

oEstrutura do Cucumber:oBusiness facing: Features, Scenarios &

StepsoTechnology Facing: Step Definitions, Support

Code & Automation Library

Page 29: Cucumber-QA_Night

Resumo

o Melhores práticas:o Escrever features declarativaso Inserir narrative nas featureso Evitar steps conjuntivoso Reusar step definitionso Não abusar do uso de backgrounds

Page 30: Cucumber-QA_Night

Referenceso Test automation with Cucumber-JVM:

http://pt.slideshare.net/alan_parkinson/test-automation-with-cucumberjvm

o Code Centric: https://blog.codecentric.de/en/2013/08/cucumber-setup-basics/

o Code Centric: http://blog.codeship.io/2013/05/21/Testing-Tuesday-6-Top-5-Cucumber-best-practices.html

o The Cucumber Book: Behaviour-Driven Development for Testers and Developers, by Matt Wynne and Aslak Hellesøy

o Cucumber JVM: https://github.com/cucumber/cucumber-jvm