Pronounced "queue united"
Tests are run with PhantomJS if available, otherwise Rhino (Java) is used. Give it a try and let me know if you have any feedback.
Install with RubyGems.
$ gem install qunited
If you are using Bundler you can add QUnited to your Gemfile. With Rails add QUnited to the test and development groups.
# In Gemfile gem 'coffee-script' # Optional, only needed if using CoffeeScript gem 'qunited'
# With Rails group :test, :development do gem 'coffee-script' # Optional gem 'qunited' end
require 'qunited/rake_task' QUnited::RakeTask.new do |t| t.source_files = ['lib/js/jquery.js', 'lib/js/my_app_1.js', 'lib/js/my_app_2.js'] t.test_files = 'test/js/**/*.js' end
You can also use an array to configure the test files but a glob pattern might be more convenient since test files usually do not need to be loaded in a particular order.
If you have some extra test helper libraries you would like to include (stubs, mocks) or files with other custom test setup, you can specify them as
QUnited::RakeTask.new do |t| t.source_files = ['lib/js/jquery.js', 'lib/js/my_app_1.js', 'lib/js/my_app_2.js'] t.helper_files = ['test/helpers/sinon-1.6.0.js'] t.test_files = 'test/js/**/*.js' end
These will be loaded after source files and before running tests. Separating helpers this way is merely for convenience and has the same effect as just including them last with your source files.
CoffeeScript is also supported. If any included source or test files have the
Specifying a driver
QUnited uses various drivers to set up the environment the tests run in (see below for more details). By default it tries to Just Work and find an available driver to use. You may want to lock down the driver (recommended) so your tests are consistent. To do this add a bit more configuration to the Rake task.
QUnited::RakeTask.new do |t| t.source_files = ['lib/js/jquery.js', 'lib/js/my_app'] t.test_files = 'test/js/**/*.js' t.driver = :phantomjs # Always use PhantomJS to run tests. Fail if it's not available. end
Available drivers are
:rhino. If no driver is specified QUnited will run tests with the best available driver, looking for them in that order.
Once the Rake task is configured as described above, run tests like this:
$ rake qunited
You should get output similar to minitest or Test::Unit
You can change the name of the task...
QUnited::RakeTask.new('test:js') do |t| # ... end
and run accordingly.
$ rake test:js
Running tests in your browser
If you've used QUnit before you've probably run tests in a browser. This is a lot of fun and makes for super quick development.
$ rake qunited:server
Then visit http://localhost:3040 in your browser and there they are.
If you specified your own task name then just append ':server' to the end. So if your task name is
test:js then run the server with the following.
$ rake test:js:server
If the default port of 3040 doesn't suit you then choose one you like.
QUnited::RakeTask.new('test:js') do |t| t.server_port = 8888 # ... end
PhantomJS is a headless WebKit. It is fast and provides an accurate browser environment (since it is a browser).
Find out how to install it here or just
brew install phantomjs if you have Homebrew.
This driver is considered available if the
phantomjs executable is on your $PATH.
Rhino + Envjs
Install Java 1.1 or greater to make this work.
This driver is considered available if you have Java 1.1 or greater and the
java executable is on your $PATH.
QUnited builds on the following projects:
QUnited is MIT licensed