Skip to main content
Why should we use automatic
      test framework?
A long long story…
Why should we choose
                ?
Test Driven Development
cCan you understand it?

       No, I can’t
Behavior Driven Development
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
Everyone can read it
Everyone can write it

Include people who don’t speak English
How does it test?
Open a real browser
Behave as a real user
Apply to any page, any website
Not only BDD
But also DDD

Document Driven Development
Cucumber Style Document
More secrets ?
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
Have a try ?

Let’s write a simple Cucumber test case
Sign up an Account
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 case
end

$ bundle install
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
features/support/env.rb
require 'cucumber/rails’

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

ActionController::Base.allow_rescue = false

begin
 DatabaseCleaner.strategy = :transaction
rescue 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
features/sign_up.feature
Feature: Sign up

 Scenario: I will register a user with email "zhour@vmware.com" and
password "vmware”

  Given I fill in email "zhour@vmware.com" and password "vmware" in sign
up page
  When I press "Sign up"
  Then I should see "Page#index"
$ rake cucumber
features/step_definitions/sign_up.rb
it works
Firefox
Thanks