Introduce cucumber

32

description

It's easy

Transcript of Introduce cucumber

Page 1: Introduce cucumber
Page 2: Introduce cucumber

Why should we use automatic test framework?

Page 3: Introduce cucumber

A long long story…

Page 4: Introduce cucumber

Why should we choose

?

Page 5: Introduce cucumber

Test Driven Development

Page 6: Introduce cucumber
Page 7: Introduce cucumber

cCan you understand it?

No, I can’t

Page 8: Introduce cucumber

Behavior Driven Development

Page 9: Introduce cucumber

Feature: Now User has given all his basic info and decided which products he will buy, then he forward into the last process - pay the money. /registration/business_pay will summarize the price(including tax and discount) he will pay and let user fill in his credit card info, when he presses "Confirm", it will charge his credit card.

Scenario: Now user input credit card info and press "Confirm", the page will submit his info to AriaSystem, AriaSystem will validate his credit card info, charge his credit card and return some data to our database. Then our database will save his personal info and partner info. If all these work well, user will be redirected to /registration/business_finish.

Given I reach /registration/business_pay When I fill in basic info into /registration/business_pay And I press "Confirm" Then I should see "Please wait..." And I waiting for being redirected to "/registration/business_finish" And all MozyPro data in Database is correct

Page 10: Introduce cucumber

Everyone can read it

Page 11: Introduce cucumber

Everyone can write it

Include people who don’t speak English

Page 12: Introduce cucumber
Page 13: Introduce cucumber

How does it test?

Page 14: Introduce cucumber

Open a real browser

Page 15: Introduce cucumber

Behave as a real user

Page 16: Introduce cucumber

Apply to any page, any website

Page 17: Introduce cucumber

Not only BDD

Page 18: Introduce cucumber

But also DDD

Document Driven Development

Page 19: Introduce cucumber

Cucumber Style Document

Page 20: Introduce cucumber

More secrets ?

Page 21: Introduce cucumber

Step Definitions

Given /^I am in "([^"]*)"$/ do |url|visit mozy_url(url, :https => true)

end

Then /^I would be redirected to "([^"]*)"$/ do |url|page.current_url.should be_include?

mozy_url(url, :https => true)end

Page 22: Introduce cucumber

Have a try ?

Let’s write a simple Cucumber test case

Page 23: Introduce cucumber

Sign up an Account

Page 24: Introduce cucumber

Gemfile

group :test do gem 'cucumber' gem 'cucumber-rails', require: false gem 'capybara', git: 'https://github.com/jnicklas/capybara.git' gem 'rspec' #use rspec expectation gem 'Selenium' #use firefox to test gem 'database_cleaner' #clean database after each test caseend

$ bundle install

Page 25: Introduce cucumber

Install Cucumber$ rails generate cucumber:install create config/cucumber.yml create script/cucumber chmod script/cucumber create features/step_definitions create features/support create features/support/env.rb exist lib/tasks create lib/tasks/cucumber.rake gsub config/database.yml gsub config/database.yml force config/database.yml

Page 26: Introduce cucumber

features/support/env.rbrequire 'cucumber/rails’

Capybara.default_selector = :cssCapybara.default_driver = :selenium #add this line

ActionController::Base.allow_rescue = false

begin DatabaseCleaner.strategy = :transactionrescue NameError raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."End

Cucumber::Rails::Database.javascript_strategy = :truncation

Page 27: Introduce cucumber

features/sign_up.featureFeature: Sign up

Scenario: I will register a user with email "[email protected]" and password "vmware”

Given I fill in email "[email protected]" and password "vmware" in sign up page When I press "Sign up" Then I should see "Page#index"

Page 28: Introduce cucumber

$ rake cucumber

Page 29: Introduce cucumber

features/step_definitions/sign_up.rb

Page 30: Introduce cucumber

it works

Page 31: Introduce cucumber

Firefox

Page 32: Introduce cucumber

Thanks