Skip to content
Dan Rice edited this page Jun 11, 2014 · 10 revisions

Testing Tracks is fairly simple. For its tests two different technologies are used:

  • minitest for unit, functional, and integration tests (in /test)
  • Cucumber with Capybara for acceptance tests (in /features)

Setup

Gems

The tests make use of some gems which need to be installed first. If you have previously done a bundle install --without development test you will need to edit your .bundle/config and re-run bundle install.

Database

Ensure you have the test section properly configured in your config/database.yml.

Since Rails 4.1, the test environment automatically loads the database schema, so you do not need to run the migrations.

Running the tests

Running the unit, functional, and integration tests

To run the entire minitest suite, from the root directory of the project, run

bin/rake test

To run an individual test file, append the path to the file, as in

bin/rake test test/models/project_test.rb

To run a single test, include the name of the file and the name of the test itself, e.g.

bin/rake test test/models/project_test.rb test_has_default_context

Running the acceptance tests

Acceptance tests are written using Cucumber. For those features that require JavaScript/AJAX, Tracks uses Capybara and Selenium.

To run all the features excluding the work-in-progress (wip) features, run

bin/cucumber

This will execute all features, including those using Selenium.

To run the features that are work in progress run these:

bin/rake cucumber:wip

To run an individual test file, append the path to the file, as in

bin/cucumber features/calendar.feature

To run a single test, include the path to the file and the test's starting line number, as in

bin/cucumber features/calendar.feature:45

If you encounter problems running selenium tests, look at the Problems with cucumber selenium tests section below.

Running the tests headless

All tests will run on a headless setup except for the selenium tests. They will need a webbrowser which will need a running X-server.

You can solve this by running a virtual framebuffer X server or by using the capybara-webkit driver.

Using webkit

Uncomment the capybara-webkit gem in the Gemfile and run bundle install. This will need the Qt development libraries on your system.

Run the features using webkit:

bundle exec rake cucumber JS_DRIVER=webkit

Framebuffer

For the framebuffer in Fedora, you need to install the packages xorg-x11-server-Xvfb and xorg-x11-apps

Xvfb :99 -ac -screen 0 1024x768x16 &

DISPLAY=:99.0 bundle exec rake cucumber:selenium

killall Xvfb

Running the old browser-based Selenium test suite

We are migrating from the selenium test suite in the browser to cucumber and selenium on webrat. To run the selenium scripts that are not yet migrated, the following still applies:

To run the suite simply run Tracks in the test environment:

bundle exec script/server -e test

in a separate command window, then run

bundle exec rake test:acceptance

and Firefox will pop up and run the suite. If this does not work, you can run the suite manually by launching the server in test mode with the command above, and navigating to

http://localhost:3000/selenium/ in your browser of choice.

Problems with cucumber selenium tests

Tests doesn't start

Firefox 3.x is required to run the selenium tests properly. It's also recommended to use an English version, to avoid problems due to the locale. You can get an old version of firefox here.

Sqlite3 Lock exceptions

In the default settings sqlite locks the db immediately. This behavior can cause problems with the fast executing online tests. Add a timeout to the database.yml configuration file to avoid these errors. For example:

test: &TEST
    adapter: sqlite3
    database: db/test.db
    timeout: 10000

Clone this wiki locally