Opening
Today we're going to familiarize ourselves with rails ' integration testing integration test.
Brief introduction
Integration testing is primarily about testing the interactions between multiple controller, and testing the more important workflows in the application to verify that these workflows are in line with the expected assumptions.
Unlike unit tests and functional tests, they are automatically added. Integration testing needs to be added manually, and rails provides a command
Rails Generate Integration_test
You can create integration tests in the Test/integration folder by command.
$ rails Generate integration_test user_flows
exists test/integration/
create Test/integration/user _flows_test.rb
Let's take a look at some of the common help methods used in integration testing.
Https
Returns true if the session is simulating an HTTPS request.
https!
Allows you to simulate HTTPS requests.
host!
Allows you to set the host name in the next request.
redirect?
Returns true if the last request was a jump.
follow_redirect!
followed by a jump response
Request_via_redirect (Http_method, path, [parameters], [headers])
Sends an HTTP request to the specified path, optionally parameters, optional headers, and then a jump.
Post_via_redirect (path, [parameters], [headers])
Send a POST request to the path you specify, optional parameters, optional headers, and then a jump.
Get_via_redirect (path, [parameters], [headers])
Sends a GET request to the specified path, optionally parameters, optionally headers, followed by a jump.
Put_via_redirect (path, [parameters], [headers])
Sends the PUT request to the specified path, optionally parameters, optional headers, and then a jump.
Delete_via_redirect (path, [parameters], [headers])
Sends a delete request to the specified path, optionally parameters, optional headers, and then a jump.
Open_session
To open a new session
Example
Let's add some code to the test/integration/user_flows_test.rb of the integrated test file that we created.
Require ' Test_helper '
class Userflowstest < Actiondispatch::integrationtest
include Factorygirl::syntax: : Methods
def test_admin_login_and_browse_posts
user = Factorygirl.create (: user_valid) Get
"/signin"
assert_response (Post_via_redirect)
("Sessions", {:user=>{:email=> User.email,:p assword => User.password}})
assert_equal '/', path
assert_equal ' sign in successfully ', Flash[:notice] get
' admin/ Posts "
Assert_response"
assert assigns (:p osts) End
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/