Testing with Ruby on Rails
- From the moment we create a new application using the Rails command simply creates the test directory structure.
- Every time we run the generate script to create a model or a controller, Rails creates a test file to hold a corresponding test stub.
- A Rails test suite is split into three fundamental parts
a. Unit Tests – Unit tests cover model-level functionality, which generally encompasses an application’s sore business logic.
b. Functional Tests – Functional tests in Rails cover controller-level functionality and the accompanying views.
c. Integration Tests – Integration testing goes beyond the relatively isolated approaches of functional and unit testing.
4. Here we take one example of test case for Event module.
require File.dirname(__FILE__) + ‘/../test_helper’ # is the help file.
class EventTest < Test::Unit::TestCase
fixtures:Events
def test_truth
assert true
end
# This part can we replace with our real tests.
end
5. How to run the Unit Test
We need to move to command prompt and there we need to move to the application root folder
And need to execute the command: $ rake test:units.
This command will execute all the test case located in the /test/unit/ folder one by one.
6. After run the Unit Test result
We can see the rake give us a summary on command prompt of our test execution.
The results suggest that a total of Tests, Assertions, Failures and Errors.
7. How to run the Functional Test
We need to move to command prompt and there we need to move to the application root folder
And need to execute the command: $ rake test:functionals.
This command will execute all the test case located in the /test/functional/ folder one by one.
8. After run the Functional Test result
We can see the rake give us a summary on command prompt of our test execution.
The results suggest that a total of Tests, Assertions, Failures and Errors.
9. How to run complete Test Suite.
We need to move to command prompt and there we need to move to the application root folder
And need to execute the command: $ rake test.
This command will run the all test suite.
10. Revisiting the Logs
We can took a brief look at the extensive logging functionality that Active Record provides. This gave us a glimpse into the kind of automation, in terms of SQL generation, that happens behind the scenes in Rails.
Summary
A Rails is useful for us. It provides us with the facility of writing a Test Script for Unit and Functional testing.
Simultaneously it provides us with the platform to generate output. We can run the multiple Test Script at one time.
- manish's blog
- Login to post comments


