Cucumber testing
Upcoming SlideShare
Loading in...5
×
 

Cucumber testing

on

  • 921 views

Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber ...

Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing Cucumber testing

Statistics

Views

Total Views
921
Views on SlideShare
921
Embed Views
0

Actions

Likes
0
Downloads
8
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Cucumber testing Cucumber testing Document Transcript

  • Cucumber Testing Installation1. Add the gems dependencies in your application’s Gemfile, for group :test only: Gemfile1 group :test do23 # RSpec4 gem rspec gem rspec-rails56 # Cucumber7 gem cucumber-rails, :require => false8 gem database_cleaner910 end112. Run the bundle command to install the gems: bundle install3. If this is the first time you run tests on your application, don’t forget tofirst prepare your test database:rake db:migraterake db:test:load4. Those frameworks need little configuration files. They can be generated withthe following commands:
  • > rails generate rspec:installcreate .rspeccreate speccreate spec/spec_helper.rb and> rails generate cucumber:installcreate config/cucumber.ymlcreate script/cucumberchmod script/cucumbercreate features/step_definitionscreate features/supportcreate features/support/env.rbexist lib/taskscreate lib/tasks/cucumber.rakegsub config/database.ymlgsub config/database.ymlforce config/database.yml 5. Finally you can write a nice test. This tutorial will make use of Cucumber to write and run tests. Therefore I define my test in my own language in a features file: features/test_cases/simple.feature1 Feature: Simple testing23 Scenario: Arriving on home page gives a 200 response code4 When I visit the page "/" Then the response code should be "200"5
  • And I can run my test by invoking cucumber:
  • > cucumberUsing the default profile...Feature: Simple testingScenario: Arriving on home page gives a 200 response code # featurestest_casessimple.feature:3When I visit the page "/" #featurestest_casessimple.feature:4Undefined step: "I visit the page "/"" (Cucumber::Undefined)featurestest_casessimple.feature:4:in `When I visit the page "/"Then the response code should be "200" # featurestest_casessimple.feature:5Undefined step: "the response code should be "200"" (Cucumber::Undefined)featurestest_casessimple.feature:5:in `Then the response code should be "200"1 scenario (1 undefined)2 steps (2 undefined)0m0.020sYou can implement step definitions for undefined steps with these snippets:When /^I visit the page "(.*?)"$/ do |arg1|pending # express the regexp above with the code you wish you hadendThen /^the response code should be "(.*?)"$/ do |arg1|pending # express the regexp above with the code you wish you hadend
  • You can see a colored output (on Windows, you will need to use Ansicon to seethe colors), much more sexier than usual Test::Unit output.Currently our test is failing, as Cucumber does not know yet what to do with ourlanguage. As you can see at the end of the output, it suggests a nice codesnippet with a regular expression to implement the missing definition.This is a real time saver: all you have to do is copy/paste this code snippet toyour definition file, and implement it.7. So next step is to implement the missing definition, done in a definitionsfile: features/step_definitions/main_steps.rbWhen /^I visit the page "(.*?)"$/ do |iPagePath|visit iPagePathendThen /^the response code should be "(.*?)"$/ do |iResponseCode|page.status_code.should == iResponseCode.to_iendNow you can re-run your cucumber test suite and admire the result:
  • > cucumberUsing the default profile...Feature: Simple testingScenario: Arriving on home page gives a 200 response code # featurestest_casessimple.feature:3When I visit the page "/" # features/step_definitions/main_steps.rb:1Then the response code should be "200" # features/step_definitions/main_steps.rb:51 scenario (1 passed)2 steps (2 passed)0m2.551s With these you can already write a great test suite, very easy to maintain with reusable and understandable sentences in your tests. Developers working after you on your project will thank you!