Advantage of using description / script in specs? (besides syntactic sugar)

Ruby 1.9.3, Rails 3.1.10, RSpec 2.13.0, Capybara 2.2.1

I am writing tests for a Rails 3 application - a GUI for clients (and administrators) to tweak various phone settings. I wrote 6 or so spec files, with a lot of other emails previously (which I used as templates). Below is a snapshot of what the spec files look like.

# spec/features/admin/administrators_spec.rb
require 'spec_helper'
include AdministratorHelper
include Helpers
feature "Exercise Administrators page"
  include_context "shared admin context"
  background do
    visit administrators_path
  end
  scenario "show index page" do
    title.should == "Administrators"
  end
  # ... other happy path tests
  # SAD PATH TESTS #
  scenario "validation: delete no administrators", js:true do
    click_button "Delete"
    page.driver.accept_js_confirms!
    error_message("Error: You did not select any administrators for deletion.")
  end
end

      

As far as I understand, feature

/ scenario

are exclusive to Capybara ... and acceptance tests. Other staff members said that our "acceptance tests" validate everything: whether the record was saved in the database, whether the view is displayed correctly, etc. Each BOM is associated with a page in the GUI, not a model / controller.

He asked me to take a course on edX (CS169.1x) and they taught testing differently - a separate spec file for the model and controller. They also used the describe

/ context

/ method it

to write tests.

  • Is there any advantage when writing tests with describe

    / it

    over feature

    / scenario

    ? (Beyond syntactic sugar)
  • Using Capybara feature

    / scenario

    does it slow down the test suite? (Compared to using RSpec keywords)
  • What kind of tests am I writing (as explained in the code block)? Reception, unit, combination?
  • Will you write tests like the ones above to achieve higher coverage? (Our next target is → 80%).

Thank you for your help and clarification.

+3


source to share


1 answer


I think the question is a bit broad, but it can be answered with some advice and opinions based on my own experience.

  • Are there any advantages to writing tests with a description / over a function / script? (Beyond syntactic sugar)

I don't know as far as I know. However, you may find that some of the convenience features of the test environment are easier to implement in one schema than others.

  1. Using Capybara function / script, does it slow down the test suite? (Compared to using RSpec keywords)

Just using keywords won't be a big factor in processing speed. Which type of web drivers and host simulation you are using will have the greatest impact.

  1. What kind of tests am I writing (as explained in the code block)? Reception, unit, combination?

I would call them acceptance tests. However, there is not always a clear dividing line and you need to see how the tests will run and how they will be used in your development process.



A mature development pipeline might have two or three separate sets of tests used for different purposes, and likely implemented using different test frameworks. You may need a set of very fast tests (usually unit tests) implemented to quickly run automated tests of new codes.

  1. Will you write tests like the ones above to achieve higher coverage? (Our next target is → 80%).

Tests can use any function of the application available to the user, and any of your own implemented programs can be considered private. You can probably get over 80% of C0 coverage (Ruby coverage tools usually don't provide deeper details like C1), provided you don't have a lot of utility scripts or other code that isn't available to the user.


I suspect that using specific test environment keywords will have minimal impact. However, using Capybara for acceptance testing of an application through the web interface will be much slower than running unit tests at separate levels of individual modules.

The test speed can vary by several orders of magnitude. For tight unit tests around a fast module, I could expect 100 examples per second. On a web development project, I usually run 10-20 examples per second on unit tests, but maybe 1 example per second on acceptance tests (which roughly matches the rough point you get here). When using Capybara with a browser driver on a hosted copy of the site, I could run one example in 10 seconds, so a suite with more than 100 tests should only run for critical path tests like candidate versus version.

+4


source







All Articles