Smoke production tests for critical features

Use case:

  • A client wants to be sure that some critical functionality is running in their production environments. Example: their products are showing in their web shop.

Plan:

  • Create some Smoke tests against production server
  • Create a Jenkins job which executes them every hour, sending a mail if this fails

In this post we will see how to create these Smoke tests with Rspec/Capybara/Mechanize. On server you can have deployed whatever web technology (Java, PHP, Node …). Required gems:

  • Rspec: testing Ruby environment
  • Capybara: simple DSL for simulating user interaction with a web application
  • Capibara-mechanize: Capybara driver which uses mechanize to create remote server requests

So that in your Gemfile (asuming you use Bundler to manage your dependencies):

  gem 'capybara'
  gem 'capybara-mechanize'

The specification:

require 'spec_helper'
 
WEBSITE_URL = "http://www.swordshop.com"
 
feature "Critical features on: #{WEBSITE_URL}" , smoke: true do
  background do
    Capybara.run_server = false
    Capybara.app_host = WEBSITE_URL
    require 'capybara/mechanize'
    Capybara.default_driver = :mechanize
 
    visit root_path
  end
 
  scenario "root is up" do
    page.should have_content("Best Swords in the world")
  end
 
  scenario "products url is showing products" do
    within("nav") { click_on "Products" }
    page.should have_css(".product")
  end
end

Just a little great detail: include smoke tag in your excluding filters, so that this will not be mixed with your unit and functional tests:

  config.filter_run_excluding :smoke

And you can allways call these tests with the command:

rspec --tag smoke

One thought on “Smoke production tests for critical features

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>