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 heforward into the last process...
Everyone can read it
Everyone can write itInclude 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 DDDDocument Driven Development
Cucumber Style Document
More secrets ?
Step DefinitionsGiven /^I am in "([^"]*)"$/ do |url|   visit mozy_url(url, :https => true)endThen /^I would be redirected ...
Have a try ?Let’s write a simple Cucumber test case
Sign up an Account
Gemfilegroup :test do gem cucumber gem cucumber-rails, require: false gem capybara, git: https://github.com/jnicklas/capyb...
Install Cucumber$ rails generate cucumber:install    create config/cucumber.yml    create script/cucumber     chmod script...
features/support/env.rbrequire cucumber/rails’Capybara.default_selector = :cssCapybara.default_driver = :selenium         ...
features/sign_up.featureFeature: Sign up Scenario: I will register a user with email "zhour@vmware.com" andpassword "vmwar...
$ rake cucumber
features/step_definitions/sign_up.rb
it works
Firefox
Thanks
Introduce cucumber
Introduce cucumber
Introduce cucumber
Upcoming SlideShare
Loading in …5
×

Introduce cucumber

1,973 views

Published on

It's easy

Published in: Technology, Economy & Finance
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,973
On SlideShare
0
From Embeds
0
Number of Embeds
684
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduce cucumber

  1. 1. Why should we use automatic test framework?
  2. 2. A long long story…
  3. 3. Why should we choose ?
  4. 4. Test Driven Development
  5. 5. cCan you understand it? No, I can’t
  6. 6. Behavior Driven Development
  7. 7. Feature:Now User has given all his basic info and decided which products he will buy, then heforward into the last process - pay the money. /registration/business_pay will summarize theprice(including tax and discount) he will pay and let user fill in his credit card info, when hepresses "Confirm", it will charge his credit card.Scenario: Now user input credit card info and press "Confirm", the page will submit his infoto AriaSystem, AriaSystem will validate his credit card info, charge his credit card and returnsome data to our database. Then our database will save his personal info and partner info. Ifall 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
  8. 8. Everyone can read it
  9. 9. Everyone can write itInclude people who don’t speak English
  10. 10. How does it test?
  11. 11. Open a real browser
  12. 12. Behave as a real user
  13. 13. Apply to any page, any website
  14. 14. Not only BDD
  15. 15. But also DDDDocument Driven Development
  16. 16. Cucumber Style Document
  17. 17. More secrets ?
  18. 18. Step DefinitionsGiven /^I am in "([^"]*)"$/ do |url| visit mozy_url(url, :https => true)endThen /^I would be redirected to "([^"]*)"$/ do |url| page.current_url.shouldbe_include?mozy_url(url, :https => true)end
  19. 19. Have a try ?Let’s write a simple Cucumber test case
  20. 20. Sign up an Account
  21. 21. Gemfilegroup :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
  22. 22. 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
  23. 23. features/support/env.rbrequire cucumber/rails’Capybara.default_selector = :cssCapybara.default_driver = :selenium #add this lineActionController::Base.allow_rescue = falsebegin DatabaseCleaner.strategy = :transactionrescue NameError raise "You need to add database_cleaner to your Gemfile (in the :test group) if youwish to use it."EndCucumber::Rails::Database.javascript_strategy = :truncation
  24. 24. features/sign_up.featureFeature: Sign up Scenario: I will register a user with email "zhour@vmware.com" andpassword "vmware” Given I fill in email "zhour@vmware.com" and password "vmware" in signup page When I press "Sign up" Then I should see "Page#index"
  25. 25. $ rake cucumber
  26. 26. features/step_definitions/sign_up.rb
  27. 27. it works
  28. 28. Firefox
  29. 29. Thanks

×