-
-
Notifications
You must be signed in to change notification settings - Fork 537
Testing
Tracks uses two different technologies for testing:
-
minitest for unit, functional, and integration tests (in
/test
) -
Cucumber with Capybara for acceptance tests (in
/features
)
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 run bundle config --delete without
to edit your Bundler configuration, then re-run bundle install
.
Ensure you have the test
section properly configured in your config/database.yml
. The test environment should have its own database and should not share with the development or production environments.
Since Rails 4.1, the test environment automatically loads the database schema, so you do not need to run the migrations.
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
Acceptance tests are written using Cucumber. For those features that require JavaScript/AJAX, Cucumber makes use of Capybara and Selenium to automate the Firefox web browser. You will need a recent version of Firefox to run these tests.
To run the entire Cucumber test suite, from the root directory of the project, run
bin/cucumber
This will execute all features, including those using Selenium.
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, e.g.
bin/cucumber features/calendar.feature:45
Incomplete features can be marked as work-in-progress using the @wip
tag in the feature file. They will not be executed as part of the normal test runs. Instead they can be run manually with
bin/rake cucumber:wip
All tests will run on a headless setup except for the Selenium tests. They need a web browser, which requires a running X-server.
You can solve this by running a virtual framebuffer X server or by using the capybara-webkit driver.
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
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
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