Developer:Testing
From myExperiment
Testing
By Tom Eveleigh, 22th September 2008
Contents |
Background
Unit tests
Unit tests are stored in 'test/units/' and one unit test class generally tests one model class. The unit tests are currently empty but should be filled in to test model functionality.
Functional tests
Functional tests are stored in 'test/functionals/' and one functional test class generally tests one controller class.
The majority of the functional test classes contain tests for the following actions in the controllers:
- index
- show
- new
- create
- edit
- update
- destroy
Some of the functional tests are currently not implemented and should be completed when possible.
Fixtures
Fixtures are stored in the 'test/fixtures/' directory and contain sample data for the tests to use. Each test class specifies which fixtures it needs and the sample data from those fixtures is loaded into the test database before each test in the test class is run.
The sample data in the fixtures is defined in YAML and must be formatted correctly in order to be valid.
For database tables that require binary data, such as content_blobs and pictures, the fixtures use files stored in 'test/fixtures/files/' which are loaded into the fixtures using code adapted from RealityForge.org.
Test Helper
The file 'test/test_helper.rb' contains helper methods that are available to all tests. Currently, it contains only one method which creates the impression of a given user (defined in 'test/fixtures/users.yml') being logged in. This allows the testing of methods that require a logged in user, such as the 'destroy' method in all controllers.
Running the tests
Preparing the database
The following command prepares the test database and loads in the schema
rake db:test:prepare
Unit tests
To run all the unit tests, use the command
rake test:units
Functional tests
To run all the functional test, use the command
rake test:functionals
All tests
To run all of the unit and functional tests, use the command
rake test
Individual tests
Individual test files can be run by simple running the test file. For example
ruby test/functional/blobs_controller_test.rb
Individual test cases can be run by specifying the name of the test case as in the following example
ruby test/functional/blobs_controller_test.rb -n test_should_get_index
