Created
November 18, 2014 19:56
-
-
Save paulghaddad/a87d0682baf97805fbfc to your computer and use it in GitHub Desktop.
Level Up 3: Uses and understands unit, functional and integration tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. You've now written two types of tests. Name them, and explain the differences. | |
The two tests I have written thus far are unit and integration tests. Unit tests validate the functionality of individual methods, they are at a low level of the code. In contrast, integration tests are at a higher level, and test a particular feature or workflow of an application, such as going to the home page, logging in, and being redirected to a particular page. The integration tests exercises a series of actions on the application and validates the desired responses. Instead of testing individual methods, integration tests validate whether a number of methods, controllers, router, models and views work in combination in successfully performing the feature or workflow. | |
2. Name the other type of test that you haven't written yet, and write an example of one. | |
Functional Tests test the various actions of a single controller, such as: Was the web request successful? Was the user redirected to the right page? | |
An example of a functional test is validating the response of the index action of a controller and ensuring the @posts instance variable was set with a value: | |
test "should get index" do | |
get :index | |
assert_response :success | |
assert_not_nil assigns(:posts) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment