The document provides guidance on tools and processes for testing NetApp's Update Center. It recommends using RSpec for unit testing Ruby code and Selenium IDE with Firefox for integration and acceptance testing. It outlines how to set up and run tests with RSpec, including installing dependencies, preparing the database, and interpreting test outputs. Guidelines are also provided for setting up and running tests with Selenium IDE.
1. NetApp Update Center Testing
Guide
Before testing pleasemakesure you have completed the necessary configuration
outlined in the installation guide.
Testing Tools
After some experimentation we are currently using 2 main testing tools.
For Update Center unit testing in Ruby we are currently using Rspec for Rails.
For Update Center integration and acceptance testing we are using Selenium IDE with the Firefox
extension.
Rspec
For unit testing in Ruby we are currently using version 2.13.1 of a Ruby Gem named Rspec for Rails.
rspec-rails is a testing framework for Rails 3.x and 4.x. rspec-rails is a gem that wraps Rails testing
behaviors into RSpec’s example groups. For example, in RSpec the controller example group is based on
ActionController::TestCase::Behavior. There are also example groups for views and helpers
● Rspec for Rails Github Page
● Rpec Online Rdoc
● Addition Rdoc Examples and Documentation
This gem and its required setup should already be completed if you cloned the existing github
repository for Snap Creator Update Center.
If this is not the case and you need to install it, simply edit your Gemfile and add rspec-rails to both the
2. :development and :test groups in the Gemfile:
group :development, :test do
gem 'rspec-rails', '~> 2.13.1'
end
Then save the Gemfile and at the command line run command:
bundle install
This should install the required Gem. See the Installation guide for any additional setup and
configuration.
Commands for Testing with Rspec
If you have not done so first run bundle install using the command
bundle install
Next run the command
rake routes
After bundle install and rake routes complete successfully you are now able to prepare the database for
testing
Before running you test with Rspec,you need to ensure that the test database structure is current. For
this you can use the following rake commands:
rake db:migrate
...
rake db:test:load
The rake db:migrate above runs any pending migrations on the development environment and updates
db/schema.rb. The rake db:test:load recreates the test database from the current db/schema.rb.
On subsequent attempts,it is a good idea to first run the command
db:test:prepare
3. db:test:prepare will first check for pending migrations and warn you appropriately.
Check out additional useful Rake commands located at the bottom of the Testing Guide
Note: If you receive a warning about migrations after running db:test:prepare , you must first run rake
db:migrate above. See the list of useful rake commands towards the end of this document.
Now that the database is setup for testing you must first start the server for testing. Open a new
command window on the Update Center root directory. Then type the command:
rails s
This command is a shortcut for stating the server you can alternately run command:
rails server
They will both start the Update Center web server,you should see the output below after running the rails
s or rails server command
=> Booting WEBrick
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2013-10-18 03:08:44] INFO WEBrick 1.3.1
[2013-10-18 03:08:44] INFO ruby 2.0.0 (2013-06-27) [i386-mingw32]
[2013-10-18 03:08:44] INFO WEBrick::HTTPServer#start: pid=13340 port=3000
Note - You can stop the server by typing Ctrl-C in the command window running the server.
After this information is printed in the command window you are ready to start running your test. Switch
back to you first command window, then you can run all Rspec test for Snap Creator Update Center by
running the command
bundle exec rspec spec/
If you prefer to run an individual test instead of the full suite simply run the same command above with
the full path of the test file. The example below runs the test named users_pages_spec.
bundle exec rspec spec/requests/users_pages_spec.rb
Rpec output
The output from Rspec will list the time taken to run the test, the number of "examples" or test run, and
the number of failures. When all test are passing you will see a similar output as below, each dot on the
4. top line is a test that was ran. Below we took 0.27518 seconds to run the test and ran 39 tests and had 0
failures.
.......................................
Finished in 0.27518 seconds
39 examples, 0 failures
Randomized with seed 37381
If a test case fails its dot will become a 'F' to reflect the failure (see example below) and also Rspec will
also give additional information to help you locate the failure.For each failing test Rspec will list
1. the test name,
2. the assert that failed
3. the expected outcome
4. location of the file containing the failing test
An example output with a failing test is below
.........F.............................
Failures:
1) User when password confimation != password
Failure/Error: it { should_not be_valid }
expected #<User id: nil, name: "Example User", email: "user@example.com", created_at:
nil> not to be valid
# ./spec/models/user_spec.rb:88:in `block (3 levels) in <top (required)>'
Finished in 0.23503 seconds
39 examples, 1 failure
Failed examples:
rspec ./spec/models/user_spec.rb:88 # User when password confimation != password
Randomized with seed 13879
In the above output
● the test name is shown in the line
1) User when password confimation != password
● the assert that failed in the line
Failure/Error: it { should_not be_valid }
● the expected outcome in the line
expected #<User id: nil, name: "Example User", email: "user@example.com", created_at: nil> not
to be valid
5. ● the location of the file containing the failing test, the line number of the failing test and the failing test
name with the output
rspec ./spec/models/user_spec.rb:88 # User when password confirmation != password
Note if you are getting failing test that really should be passing, try restarting the server.
Selenium
For integration and acceptance testing we are using Selenium IDE. Selenium can be used in many ways.
We are using the Selenium IDE through the Selenium Firefox plugin. This testing suite is currently using
Firefox version 24 with the Selenium Plugin.
Note if you didn't have it already you will first need to install the Firefox Web Browser.
● Firefox.
Next install the Selenium IDE Plugin
● Selenium IDE Firefox Plugin
Also check out the Selenium homepage for release notes and additional examples
Below is a screen shot of the Selenium IDE plugin running in Firefox.
6. Note: The selenium folder contains a subfolder for each suite of test, for example the signin_page_test
subfolder contains the test suite for the signin page. The test suites and individual test are stored as .html
file and the full test suite for each folder will have a filename ending in test_suite. For example the test
suite for the user sign in page is named signin_page_test_suite.html and its relative path is
seleniumsignin_page_testsignin_page_test_suite.html
Using Selenium
To open a test suite, in the Selenium window you want to click File -> Open Test Suite... Then browse to
the Update Center root folder, then into the selenium folder where all Selenium test are contained. To
open the signin page test suite navigate to the folder seleniumsignin_page_test Then open the file
7. named signin_page_test_suite.html Selenium now has the test suite loaded and it is ready to run. The
example below has the signin_page_test_suite.html loaded
The individual test cases for the test suite are listed in the left column. The actual test code is located in
the right hand pane in the shot above. To run the entire test suite click the green arrow button with the
three green rectangles
To run just the single test highlighted in the left pane click the green arrow with only one green rectangle.
After running the entire test suite you will see an output screen similar the one below.
Note: annotated for detail
8. Once all test are passing you should get a output screen that looks like the one below
9. List of USEFUL rake commands and their descriptions:
Recreate the test database from the current environment's database schema
rake db:test:clone
Recreate the test database from the development structure
db:test:clone_structure
Recreate the test database from the current schema.rb
rake db:test:load
Check for pending migrations and load the test schema
rake db:test:prepare
10. Empty the test database.
rake db:test:purge
**You can see all of these rake task and their description by running*
rake --tasks --describe
Revision Date Details Author
Version1.1 10/21/2013 Updateddocument
withGithubMarkdown
JasonBrown
Version1.0 9/29/2013 CreatedTestingGuide JasonBrown