SlideShare uma empresa Scribd logo
1 de 35
Introdução a Testes Automatizados em Ruby On Rails Thiago Cifani Ayres Escola
Tópicos ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Introdução a Testes Automatizados em Ruby On Rails
Manifesto Ágil Introdução a Testes Automatizados em Ruby On Rails Fonte: http://scrumex.com.br/blog/?p=28
Tecnologias Utilizadas Introdução a Testes Automatizados em Ruby On Rails
Introdução a Testes Automatizados em Ruby On Rails ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Introdução a Testes Automatizados em Ruby On Rails # A classe Saudação class Saudacao    def initialize(name)      @name = name.capitalize    end      def sauda      puts "Olá #{@name}!"    end end   # Criar um novo objeto ola = Saudacao.new("mundo")   # Saída: "Olá Mundo!" ola.sauda 3.times { print “thiago” } #saída : thiago thiago thiago [‘um’,‘dois’,‘tres’].each {|num| puts num.capitalize } #saida Um Dois Tres “ thiago”.reverse #saída: ogaiht 1.upto(5) { |x| puts x } #saída: 1 2 3 4 5 # Declaração de Classes # Simplicidade # Legibilidade # Agilidade # Sintaxe Enxuta
Introdução a Testes Automatizados em Ruby On Rails ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Introdução a Testes Automatizados em Ruby On Rails <h1>Users#show</h1> <p>User:  <%=  @user . name  %> </p> <p>Email:  <%=  @user . email  if  @user . email  %> </p> class   UsersController   <  ApplicationController       def   show      @user  =  User . find(params [ :id ] )    end end # Model # Controller # View class User < ActiveRecord::Base has_many :teams end user.rb users_controller.rb show.html.erb
Testes Automatizados Introdução a Testes Automatizados em Ruby On Rails
Testes em Rails ,[object Object],[object Object],[object Object],[object Object],[object Object],Introdução a Testes Automatizados em Ruby On Rails should &quot;get new&quot;  do      get :new      assert_response :success    end ,[object Object]
Testes em Rails ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Introdução a Testes Automatizados em Ruby On Rails Fonte:  https://github.com/thoughtworks/letshelp.it/blob/master/test/fixtures/organizations.yml
TDD Introdução a Testes Automatizados em Ruby On Rails Test Driven Development  é uma prática de desenvolvimento que envolve escrever teste antes de escrever código a ser testado. Começa escrevendo um pequeno teste para o código que ainda não existe. [ CHE, 2010 ]
TDD Introdução a Testes Automatizados em Ruby On Rails
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],require 'spec_helper' describe  Team  do  end team_spec.rb
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],/home/thiagocifani/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.2/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant Team (NameError)
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],class Team < ActiveRecord::Base end # Saída Finished in 0 seconds 0 examples, 0 failures
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],describe Team do it &quot;should not save a Team with blank name&quot; do @team = Team.new(:name => &quot;&quot;) @team.should_not be_valid end  end team_spec.rb
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],F Failures: 1) Team should not save a Team with blank name Failure/Error: @team.should_not be_valid expected valid? to return false, got true # ./spec/models/team_spec.rb:7:in `block (2 levels) in <top (required)>' Finished in 0.04004 seconds 1 example, 1 failure rake aborted!
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],class Team < ActiveRecord::Base validates_presence_of :name end . Finished in 0.04472 seconds 1 example, 0 failures # Saída
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],describe Team do it &quot;should not save a Team with blank name&quot; do @team = Team.new(:name => &quot;&quot;) @team.should_not be_valid end  end
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],describe Team do it { should validates_presence_of :name} end
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],describe Team do it { should validates_presence_of :name} it { should validates_uniqueness_of :name} end . F Failures: 1) Team  Failure/Error: it {should validate_uniqueness_of :name} Can't find first Team # ./spec/models/team_spec.rb:10:in `block (2 levels) in <top (required)>' Finished in 0.13438 seconds 2 examples, 1 failure rake aborted!
TDD Introdução a Testes Automatizados em Ruby On Rails ,[object Object],class Team < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name end .. Finished in 0.04472 seconds 2 example, 0 failures # Saída describe Team do before do @team = Factory(:team)  end it { should validates_presence_of :name} it { should validates_uniqueness_of :name} end
BDD Introdução a Testes Automatizados em Ruby On Rails BDD (Behavior Driven Development) baseia-se na descrição do comportamento da aplicação baseado na opinião dos clientes.
BDD Introdução a Testes Automatizados em Ruby On Rails Os três princípios são:  O suficiente é suficiente:  Designs gigantescos, análises intermináveis. Deve-se fazer o  menos possível para começar e, qualquer coisa além disso, é um desperdício. Isso também  nos ajuda a pensar em sempre automatizar as tarefas repetitivas como deploy e build;  Entregar algo de valor:  Se você está fazendo algo que não tem valor ou não está  aumentando sua habilidade de entregar valor, pare e faça outra coisa;  Tudo é comportamento:  Independente se é em nível de codificação, aplicação ou algo  além, deve-se sempre usar o mesmo pensamento e linguística de construção para descrever  comportamento em qualquer nível de granularidade.
Rspec Introdução a Testes Automatizados em Ruby On Rails O RSpec é uma DSL (Domain-Specific Language) para especificar o comportamento desejado do código Ruby
Rspec Introdução a Testes Automatizados em Ruby On Rails •  Subject Code : O código cujo comportamento está sendo especificando com o RSpec;  •  Expectation:  Uma expressão de como o subject code deve se comportar;  •  Code Example:  Um exemplo executável de como o subject code pode ser usado e como  o seu comportamento esperado (expresso com  expectations) em um determinado contexto;  •  Example group :  Grupo de code examples.
Rspec Introdução a Testes Automatizados em Ruby On Rails require 'spec_helper'  describe Team do  before(:each) do  @team = Factory(:team)  end  it {should validate_presence_of :name}  it {should validate_uniqueness_of :name}  it {should belong_to :user }  end  end  end
Cucumber Introdução a Testes Automatizados em Ruby On Rails O Cucumber é um  framework de alto nível para testes automatizados. Mais utilizado para  testes de aceitação, ele permite descrever uma estória e implementar o código de acordo com essa estória.
Cucumber Introdução a Testes Automatizados em Ruby On Rails •  Feature : Define a funcionalidade do sistema.  •  Scenario : Define um possível cenário da aplicação.  •  Given : Usado para determinar o estado da aplicação no momento que o teste é executado;  •  When : Usado para especificar as ações a serem executadas;  •  Then : Usado para especificar o resultado esperado.  •  And : Usa-se como adendo, podendo unir vários Given/When/Then.
Feature Introdução a Testes Automatizados em Ruby On Rails Feature: home  As a user  I want to see the teams link  to go to the team list page  Scenario: Go to the team list page  Given I visit the home page  When I click on Teams link  Then should go to the team list page rake cucumber
Steps Introdução a Testes Automatizados em Ruby On Rails Given /^I visit the home page$/ do  peding… end  When /^I click on Teams link$/ do  pending… end  Then /^should go to the team list page$/ do  pending… end
Steps Introdução a Testes Automatizados em Ruby On Rails Given /^I visit the home page$/ do  visit root_path  end  When /^I click on Teams link$/ do  click_link &quot;Teams List&quot;  end  Then /^should go to the team list page$/ do  visit teams_path  end
Conclusão Introdução a Testes Automatizados em Ruby On Rails Utilizando  testes automatizados  podemos garantir  que o  software que estamos escrevendo realmente atende a necessidade estabelecida por nosso cliente. Quando escrevemos o código e terminamos, realmente  terminamos.
FIM Introdução a Testes Automatizados em Ruby On Rails

Mais conteúdo relacionado

Mais procurados

Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetesDongwon Kim
 
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화OpenStack Korea Community
 
Docker London: Container Security
Docker London: Container SecurityDocker London: Container Security
Docker London: Container SecurityPhil Estes
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台Bo-Yi Wu
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleRobert Reiz
 
DCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDocker, Inc.
 
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020AWSKRUG - AWS한국사용자모임
 
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker images
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker imagesRootedCON 2017 - Docker might not be your friend. Trojanizing Docker images
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker imagesDaniel Garcia (a.k.a cr0hn)
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker IntroductionSparkbit
 
Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Katherine Golovinova
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An IntroductionPOSSCON
 
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版junichi anno
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in DockerDocker, Inc.
 
A guide to getting started with WebdriverIO
A guide to getting started with WebdriverIOA guide to getting started with WebdriverIO
A guide to getting started with WebdriverIONilenth Selvaraja
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorialKaty Slemon
 
Introduction to docker and docker compose
Introduction to docker and docker composeIntroduction to docker and docker compose
Introduction to docker and docker composeLalatendu Mohanty
 

Mais procurados (20)

Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화
[OpenStack 하반기 스터디] Docker를 이용한 OpenStack 가상화
 
Docker London: Container Security
Docker London: Container SecurityDocker London: Container Security
Docker London: Container Security
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台
 
Intro to kubernetes
Intro to kubernetesIntro to kubernetes
Intro to kubernetes
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & Ansible
 
DCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best PracticesDCSF19 Dockerfile Best Practices
DCSF19 Dockerfile Best Practices
 
Docker swarm
Docker swarmDocker swarm
Docker swarm
 
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020
쿠알못이 Amazon EKS로 안정적인 서비스 운영하기 - 최용호(넥슨코리아) :: AWS Community Day 2020
 
Implementing ossec
Implementing ossecImplementing ossec
Implementing ossec
 
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker images
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker imagesRootedCON 2017 - Docker might not be your friend. Trojanizing Docker images
RootedCON 2017 - Docker might not be your friend. Trojanizing Docker images
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?Infrastructure as Code for Azure: ARM or Terraform?
Infrastructure as Code for Azure: ARM or Terraform?
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in Docker
 
A guide to getting started with WebdriverIO
A guide to getting started with WebdriverIOA guide to getting started with WebdriverIO
A guide to getting started with WebdriverIO
 
Flask jwt authentication tutorial
Flask jwt authentication tutorialFlask jwt authentication tutorial
Flask jwt authentication tutorial
 
Introduction to docker and docker compose
Introduction to docker and docker composeIntroduction to docker and docker compose
Introduction to docker and docker compose
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 

Semelhante a Testes Automatizados em Ruby on Rails

Introdução á linguagem Ruby com aplicativo em Rails
Introdução á linguagem Ruby com aplicativo em RailsIntrodução á linguagem Ruby com aplicativo em Rails
Introdução á linguagem Ruby com aplicativo em Railsoverduka
 
Desenvolvimento web com Ruby on Rails (parte 1)
Desenvolvimento web com Ruby on Rails (parte 1)Desenvolvimento web com Ruby on Rails (parte 1)
Desenvolvimento web com Ruby on Rails (parte 1)Joao Lucas Santana
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAThiago Cifani
 
Introdução ao Ruby on Rails
Introdução ao Ruby on RailsIntrodução ao Ruby on Rails
Introdução ao Ruby on RailsJuan Maiz
 
Minicurso de Rails - WTISC 2014
Minicurso de Rails - WTISC 2014Minicurso de Rails - WTISC 2014
Minicurso de Rails - WTISC 2014Zarathon Maia
 
Ruby, Rails e Diversão (Campus Party Brasil 2009)
Ruby, Rails e Diversão (Campus Party Brasil 2009)Ruby, Rails e Diversão (Campus Party Brasil 2009)
Ruby, Rails e Diversão (Campus Party Brasil 2009)Julio Monteiro
 
Esta começando a programar para a web? Então começe com Rails
Esta começando a programar para a web? Então começe com RailsEsta começando a programar para a web? Então começe com Rails
Esta começando a programar para a web? Então começe com Railsismaelstahelin
 
Mini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOLMini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOLtarginosilveira
 
Criando APIs com Node e TypeScript
Criando APIs com Node e TypeScriptCriando APIs com Node e TypeScript
Criando APIs com Node e TypeScriptAndre Baltieri
 
Rails - EXATEC2009
Rails - EXATEC2009Rails - EXATEC2009
Rails - EXATEC2009Caue Guerra
 
Desenvolvimento ágil de software com Ruby on Rails
Desenvolvimento ágil de software com Ruby on RailsDesenvolvimento ágil de software com Ruby on Rails
Desenvolvimento ágil de software com Ruby on RailsLucas Caton
 
Curso de Ruby on Rails
Curso de Ruby on RailsCurso de Ruby on Rails
Curso de Ruby on RailsCJR, UnB
 
Workshop Ruby on Rails dia 2 ruby-pt
Workshop Ruby on Rails dia 2  ruby-ptWorkshop Ruby on Rails dia 2  ruby-pt
Workshop Ruby on Rails dia 2 ruby-ptPedro Sousa
 
Quick introduction to Ruby on Rails
Quick introduction to Ruby on RailsQuick introduction to Ruby on Rails
Quick introduction to Ruby on RailsWhitesmith
 

Semelhante a Testes Automatizados em Ruby on Rails (20)

Introdução á linguagem Ruby com aplicativo em Rails
Introdução á linguagem Ruby com aplicativo em RailsIntrodução á linguagem Ruby com aplicativo em Rails
Introdução á linguagem Ruby com aplicativo em Rails
 
Ruby & Rails
Ruby & RailsRuby & Rails
Ruby & Rails
 
Desenvolvimento web com Ruby on Rails (parte 1)
Desenvolvimento web com Ruby on Rails (parte 1)Desenvolvimento web com Ruby on Rails (parte 1)
Desenvolvimento web com Ruby on Rails (parte 1)
 
Curso Ruby
Curso RubyCurso Ruby
Curso Ruby
 
Palestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVAPalestra Desenvolvimento Ágil para Web com ROR UVA
Palestra Desenvolvimento Ágil para Web com ROR UVA
 
Introdução ao Ruby on Rails
Introdução ao Ruby on RailsIntrodução ao Ruby on Rails
Introdução ao Ruby on Rails
 
Palestra Ruby
Palestra RubyPalestra Ruby
Palestra Ruby
 
Minicurso de Rails - WTISC 2014
Minicurso de Rails - WTISC 2014Minicurso de Rails - WTISC 2014
Minicurso de Rails - WTISC 2014
 
Rails na pratica
Rails na praticaRails na pratica
Rails na pratica
 
Ruby, Rails e Diversão (Campus Party Brasil 2009)
Ruby, Rails e Diversão (Campus Party Brasil 2009)Ruby, Rails e Diversão (Campus Party Brasil 2009)
Ruby, Rails e Diversão (Campus Party Brasil 2009)
 
Esta começando a programar para a web? Então começe com Rails
Esta começando a programar para a web? Então começe com RailsEsta começando a programar para a web? Então começe com Rails
Esta começando a programar para a web? Então começe com Rails
 
Aula3
Aula3Aula3
Aula3
 
Behaviour-Driven Development com Ruby
Behaviour-Driven Development com RubyBehaviour-Driven Development com Ruby
Behaviour-Driven Development com Ruby
 
Mini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOLMini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOL
 
Criando APIs com Node e TypeScript
Criando APIs com Node e TypeScriptCriando APIs com Node e TypeScript
Criando APIs com Node e TypeScript
 
Rails - EXATEC2009
Rails - EXATEC2009Rails - EXATEC2009
Rails - EXATEC2009
 
Desenvolvimento ágil de software com Ruby on Rails
Desenvolvimento ágil de software com Ruby on RailsDesenvolvimento ágil de software com Ruby on Rails
Desenvolvimento ágil de software com Ruby on Rails
 
Curso de Ruby on Rails
Curso de Ruby on RailsCurso de Ruby on Rails
Curso de Ruby on Rails
 
Workshop Ruby on Rails dia 2 ruby-pt
Workshop Ruby on Rails dia 2  ruby-ptWorkshop Ruby on Rails dia 2  ruby-pt
Workshop Ruby on Rails dia 2 ruby-pt
 
Quick introduction to Ruby on Rails
Quick introduction to Ruby on RailsQuick introduction to Ruby on Rails
Quick introduction to Ruby on Rails
 

Testes Automatizados em Ruby on Rails

  • 1. Introdução a Testes Automatizados em Ruby On Rails Thiago Cifani Ayres Escola
  • 2.
  • 3. Manifesto Ágil Introdução a Testes Automatizados em Ruby On Rails Fonte: http://scrumex.com.br/blog/?p=28
  • 4. Tecnologias Utilizadas Introdução a Testes Automatizados em Ruby On Rails
  • 5.
  • 6. Introdução a Testes Automatizados em Ruby On Rails # A classe Saudação class Saudacao    def initialize(name)      @name = name.capitalize    end      def sauda      puts &quot;Olá #{@name}!&quot;    end end   # Criar um novo objeto ola = Saudacao.new(&quot;mundo&quot;)   # Saída: &quot;Olá Mundo!&quot; ola.sauda 3.times { print “thiago” } #saída : thiago thiago thiago [‘um’,‘dois’,‘tres’].each {|num| puts num.capitalize } #saida Um Dois Tres “ thiago”.reverse #saída: ogaiht 1.upto(5) { |x| puts x } #saída: 1 2 3 4 5 # Declaração de Classes # Simplicidade # Legibilidade # Agilidade # Sintaxe Enxuta
  • 7.
  • 8. Introdução a Testes Automatizados em Ruby On Rails <h1>Users#show</h1> <p>User: <%= @user . name %> </p> <p>Email: <%= @user . email if @user . email %> </p> class UsersController < ApplicationController       def show      @user = User . find(params [ :id ] )    end end # Model # Controller # View class User < ActiveRecord::Base has_many :teams end user.rb users_controller.rb show.html.erb
  • 9. Testes Automatizados Introdução a Testes Automatizados em Ruby On Rails
  • 10.
  • 11.
  • 12. TDD Introdução a Testes Automatizados em Ruby On Rails Test Driven Development é uma prática de desenvolvimento que envolve escrever teste antes de escrever código a ser testado. Começa escrevendo um pequeno teste para o código que ainda não existe. [ CHE, 2010 ]
  • 13. TDD Introdução a Testes Automatizados em Ruby On Rails
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. BDD Introdução a Testes Automatizados em Ruby On Rails BDD (Behavior Driven Development) baseia-se na descrição do comportamento da aplicação baseado na opinião dos clientes.
  • 25. BDD Introdução a Testes Automatizados em Ruby On Rails Os três princípios são: O suficiente é suficiente: Designs gigantescos, análises intermináveis. Deve-se fazer o menos possível para começar e, qualquer coisa além disso, é um desperdício. Isso também nos ajuda a pensar em sempre automatizar as tarefas repetitivas como deploy e build; Entregar algo de valor: Se você está fazendo algo que não tem valor ou não está aumentando sua habilidade de entregar valor, pare e faça outra coisa; Tudo é comportamento: Independente se é em nível de codificação, aplicação ou algo além, deve-se sempre usar o mesmo pensamento e linguística de construção para descrever comportamento em qualquer nível de granularidade.
  • 26. Rspec Introdução a Testes Automatizados em Ruby On Rails O RSpec é uma DSL (Domain-Specific Language) para especificar o comportamento desejado do código Ruby
  • 27. Rspec Introdução a Testes Automatizados em Ruby On Rails • Subject Code : O código cujo comportamento está sendo especificando com o RSpec; • Expectation: Uma expressão de como o subject code deve se comportar; • Code Example: Um exemplo executável de como o subject code pode ser usado e como o seu comportamento esperado (expresso com expectations) em um determinado contexto; • Example group : Grupo de code examples.
  • 28. Rspec Introdução a Testes Automatizados em Ruby On Rails require 'spec_helper' describe Team do before(:each) do @team = Factory(:team) end it {should validate_presence_of :name} it {should validate_uniqueness_of :name} it {should belong_to :user } end end end
  • 29. Cucumber Introdução a Testes Automatizados em Ruby On Rails O Cucumber é um framework de alto nível para testes automatizados. Mais utilizado para testes de aceitação, ele permite descrever uma estória e implementar o código de acordo com essa estória.
  • 30. Cucumber Introdução a Testes Automatizados em Ruby On Rails • Feature : Define a funcionalidade do sistema. • Scenario : Define um possível cenário da aplicação. • Given : Usado para determinar o estado da aplicação no momento que o teste é executado; • When : Usado para especificar as ações a serem executadas; • Then : Usado para especificar o resultado esperado. • And : Usa-se como adendo, podendo unir vários Given/When/Then.
  • 31. Feature Introdução a Testes Automatizados em Ruby On Rails Feature: home As a user I want to see the teams link to go to the team list page Scenario: Go to the team list page Given I visit the home page When I click on Teams link Then should go to the team list page rake cucumber
  • 32. Steps Introdução a Testes Automatizados em Ruby On Rails Given /^I visit the home page$/ do peding… end When /^I click on Teams link$/ do pending… end Then /^should go to the team list page$/ do pending… end
  • 33. Steps Introdução a Testes Automatizados em Ruby On Rails Given /^I visit the home page$/ do visit root_path end When /^I click on Teams link$/ do click_link &quot;Teams List&quot; end Then /^should go to the team list page$/ do visit teams_path end
  • 34. Conclusão Introdução a Testes Automatizados em Ruby On Rails Utilizando testes automatizados podemos garantir que o software que estamos escrevendo realmente atende a necessidade estabelecida por nosso cliente. Quando escrevemos o código e terminamos, realmente terminamos.
  • 35. FIM Introdução a Testes Automatizados em Ruby On Rails