<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jli21</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jli21"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jli21"/>
	<updated>2026-09-19T14:24:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53904</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53904"/>
		<updated>2011-10-21T03:27:25Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test?=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails?=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application?=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&amp;lt;ref&amp;gt; http://effectif.com/articles/testing-rails-with-rack-test&amp;lt;/ref&amp;gt;&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Flow of Testing in Rails=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
&lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Examples of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&amp;lt;ref&amp;gt; http://www.jetbrains.com/ruby/features/ruby_unit_testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
  should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
    ar_class = self.class.model_class&lt;br /&gt;
    found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
    assert !found_objects.blank?&lt;br /&gt;
    found_objects.each do |obj|&lt;br /&gt;
        assert block.call(obj)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    unfound_objects = ar_class.all - found_objects&lt;br /&gt;
    assert !unfound_objects.blank?&lt;br /&gt;
    unfound_objects.each do |obj|&lt;br /&gt;
        assert !block.call(obj)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include by Functional Testing?==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
&lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. &amp;lt;ref&amp;gt;Noel Rappin, edited by Colleen Toporek: Rails Test Prescriptions: Keeping Your Application Healthy, 2011.&amp;lt;/ref&amp;gt;For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;taste&amp;quot;]               flash[:taste]&lt;br /&gt;
session[&amp;quot;userid&amp;quot;]            session[:userid]&lt;br /&gt;
cookies[&amp;quot;display_post&amp;quot;]      cookies[:display_post]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Examples==&lt;br /&gt;
===Starting a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&amp;lt;ref&amp;gt;rspec-rails-1.3.4, http://rspec.info/rails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&amp;lt;ref&amp;gt;Performance Testing Rails Applications — How To? http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&amp;lt;ref&amp;gt;Ruby on Rails 3 Testing: http://jonathanhui.com/ruby-rails-3-testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53889</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53889"/>
		<updated>2011-10-21T03:22:37Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Setup and Teardown */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&amp;lt;ref&amp;gt; http://effectif.com/articles/testing-rails-with-rack-test&amp;lt;/ref&amp;gt;&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
&lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&amp;lt;ref&amp;gt; http://www.jetbrains.com/ruby/features/ruby_unit_testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
  should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
    ar_class = self.class.model_class&lt;br /&gt;
    found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
    assert !found_objects.blank?&lt;br /&gt;
    found_objects.each do |obj|&lt;br /&gt;
        assert block.call(obj)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    unfound_objects = ar_class.all - found_objects&lt;br /&gt;
    assert !unfound_objects.blank?&lt;br /&gt;
    unfound_objects.each do |obj|&lt;br /&gt;
        assert !block.call(obj)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include by Functional Testing?==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
&lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. &amp;lt;ref&amp;gt;Noel Rappin, edited by Colleen Toporek: Rails Test Prescriptions: Keeping Your Application Healthy, 2011.&amp;lt;/ref&amp;gt;For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;taste&amp;quot;]               flash[:taste]&lt;br /&gt;
session[&amp;quot;userid&amp;quot;]            session[:userid]&lt;br /&gt;
cookies[&amp;quot;display_post&amp;quot;]      cookies[:display_post]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Examples==&lt;br /&gt;
===Starting a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&amp;lt;ref&amp;gt;rspec-rails-1.3.4, http://rspec.info/rails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&amp;lt;ref&amp;gt;Performance Testing Rails Applications — How To? http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&amp;lt;ref&amp;gt;Ruby on Rails 3 Testing: http://jonathanhui.com/ruby-rails-3-testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53865</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53865"/>
		<updated>2011-10-21T03:09:38Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* What is Include By Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&amp;lt;ref&amp;gt; http://effectif.com/articles/testing-rails-with-rack-test&amp;lt;/ref&amp;gt;&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
&lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&amp;lt;ref&amp;gt; http://www.jetbrains.com/ruby/features/ruby_unit_testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
&lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. &amp;lt;ref&amp;gt;Noel Rappin, edited by Colleen Toporek: Rails Test Prescriptions: Keeping Your Application Healthy, 2011.&amp;lt;/ref&amp;gt;For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Example==&lt;br /&gt;
===Simulation a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&amp;lt;ref&amp;gt;rspec-rails-1.3.4, http://rspec.info/rails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&amp;lt;ref&amp;gt;Performance Testing Rails Applications — How To? http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&amp;lt;ref&amp;gt;Ruby on Rails 3 Testing: http://jonathanhui.com/ruby-rails-3-testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53864</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53864"/>
		<updated>2011-10-21T03:09:13Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* What is A Good Unit Testing? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&amp;lt;ref&amp;gt; http://effectif.com/articles/testing-rails-with-rack-test&amp;lt;/ref&amp;gt;&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
&lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&amp;lt;ref&amp;gt; http://www.jetbrains.com/ruby/features/ruby_unit_testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. &amp;lt;ref&amp;gt;Noel Rappin, edited by Colleen Toporek: Rails Test Prescriptions: Keeping Your Application Healthy, 2011.&amp;lt;/ref&amp;gt;For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Example==&lt;br /&gt;
===Simulation a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&amp;lt;ref&amp;gt;rspec-rails-1.3.4, http://rspec.info/rails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&amp;lt;ref&amp;gt;Performance Testing Rails Applications — How To? http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&amp;lt;ref&amp;gt;Ruby on Rails 3 Testing: http://jonathanhui.com/ruby-rails-3-testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53860</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53860"/>
		<updated>2011-10-21T03:07:15Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&amp;lt;ref&amp;gt; http://effectif.com/articles/testing-rails-with-rack-test&amp;lt;/ref&amp;gt;&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&amp;lt;ref&amp;gt; http://www.jetbrains.com/ruby/features/ruby_unit_testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. &amp;lt;ref&amp;gt;Noel Rappin, edited by Colleen Toporek: Rails Test Prescriptions: Keeping Your Application Healthy, 2011.&amp;lt;/ref&amp;gt;For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Example==&lt;br /&gt;
===Simulation a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&amp;lt;ref&amp;gt;rspec-rails-1.3.4, http://rspec.info/rails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&amp;lt;ref&amp;gt;Performance Testing Rails Applications — How To? http://rubylearning.com/blog/2011/08/14/performance-testing-rails-applications-how-to/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&amp;lt;ref&amp;gt;Ruby on Rails 3 Testing: http://jonathanhui.com/ruby-rails-3-testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53835</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53835"/>
		<updated>2011-10-21T02:46:22Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* The MVC Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&amp;lt;ref&amp;gt;http://msdn.microsoft.com/en-us/library/ff649643.aspx&amp;lt;/ref&amp;gt;&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Example==&lt;br /&gt;
===Simulation a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53825</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53825"/>
		<updated>2011-10-21T02:40:59Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Functional Testing for Controllers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==What to Test in Functional Testing?==&lt;br /&gt;
The goal of the functional testing includes:&lt;br /&gt;
•	To ensure that a normal user request can trigger the ActiveRecord calls as expected and pass the correct data to the view.&lt;br /&gt;
•	To ensure that an invalid user request is properly handled&lt;br /&gt;
•	To ensure a series of security check. For example, requiring logins for the web application; only the admin have the grant to delete other users; For the users who enter URL for a resource, the page returned by the application should not be blocked or diverted.&lt;br /&gt;
&lt;br /&gt;
==Functional Testing Example==&lt;br /&gt;
===Simulation a Controller Call===&lt;br /&gt;
The first step to initialize the functional testing is to simulate a controller call. Let us look a simple example:&lt;br /&gt;
&amp;lt;pre&amp;gt;setup :generic_setup&lt;br /&gt;
def generic_setup&lt;br /&gt;
@task = Task.create&lt;br /&gt;
login_as :admin&lt;br /&gt;
end&lt;br /&gt;
test &amp;quot;should show a task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task.id.to_s&lt;br /&gt;
assert_equal(@task.id, assigns(:task).id)&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template :show&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The test methods for each HTTP verb (get( ), post( ), put( ), and delete( )) is provided by Rails. They works in the same way. The first argument to the simulated call is the controller method to invoke. The second argument contains the key/value pairs that become the params of the call. The Rails holds the convention of placing complex data types into parameter names. Therefore, :task =&amp;gt; {:project =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}} creates params[:task][:project][:id] = &amp;quot;3&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If  a session is getting a user ID and current project, and the flash is getting a notice:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
get :show, {:id =&amp;gt; @task.id.to_s}, {:user_id =&amp;gt; &amp;quot;3&amp;quot;, :current_project =&amp;gt; @project.id.to_s}, {:notice =&amp;gt; &amp;quot;flash test&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The xhr( ) method simulates an Ajax call to the controller. The signature of the method is a little different; the first argument is the HTTP verb, the second is the controller method, and the remaining arguments match the order of the other HTTP mimic methods:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;test &amp;quot;my ajax call&amp;quot; do&lt;br /&gt;
xhr :post, :create, :task =&amp;gt; {:id =&amp;gt; &amp;quot;3&amp;quot;}&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The controller will respond to a test call made with the xhr( ) exactly the way it would respond to an actual Ajax request. That is to say, if you use the more modern respond_to blocks, then the request will match&lt;br /&gt;
the format.j s block. Alternately, the controller method xhr? will return true for the action being tested.&lt;br /&gt;
&lt;br /&gt;
===Testing Controller Response===&lt;br /&gt;
After you submit a request, you expect the web application returns the HTTP status code as you expected and that appropriate Rails template is placed in charge of returning the response. Rails provides three assertion methods to help: assert_redirected_to( ), assert_response( ), and assert_template( ). &lt;br /&gt;
The following code exemplifies using assert_response( ) and assert_template( ) to verify whether a normal HTTP response is return and not directed.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;successful index request&amp;quot; do&lt;br /&gt;
get :index&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_template &amp;quot;index&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The assert_response( ) actually verifies the response code sent by Rails to the browser. The assert_template( ) verifies which template Rails uses to generate the response. The template name is specified exactly as it would be in the controller using render :action—the template name can be a string or&lt;br /&gt;
a symbol. If the argument is just a single string or symbol, then it is checked against the name of the main template that rendered the action. &lt;br /&gt;
&lt;br /&gt;
For a redirect, Rails provides assert_redirected_to( ), which takes as an argument any object that can be resolved into a URL.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert_redirected_to :controller =&amp;gt; :task, :action =&amp;gt; :show, :id =&amp;gt;3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Testing Returned Data===&lt;br /&gt;
The four collections provided by Rails (assigns, session, cookies, and flash) can be used to verify the data generated by the controller method. The assigns, a hash of instance variables created in the controller, is the most commonly used. A typical use might look like this, with a common use of assigns, and a frankly contrived use of session:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should show task&amp;quot; do&lt;br /&gt;
get :show, :id =&amp;gt; @task_1.id&lt;br /&gt;
assert_response :success&lt;br /&gt;
assert_equal @task_1.id, assigns(:task).id&lt;br /&gt;
assert_equal &amp;quot;task/show&amp;quot;, session[:last_page]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53815</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53815"/>
		<updated>2011-10-21T02:34:51Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* What is Include By Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_select(selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on the selected elements through the selector. &lt;br /&gt;
|-&lt;br /&gt;
| assert_select(element, selector, [equality], [message]) &lt;br /&gt;
| ensures that the equality condition is met on all the selected elements through the selector starting from the element (instance ofHTML::Node) and its descendants.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_email&lt;br /&gt;
| Allows you to make assertions on the body of an e-mail.&lt;br /&gt;
|-&lt;br /&gt;
| assert_select_encoded&lt;br /&gt;
| Allows you to make assertions on encoded HTML. It does this by un-encoding the contents of each element and then calling the block with all the un-encoded elements.&lt;br /&gt;
|-&lt;br /&gt;
| css_select(selector)orcss_select(element, selector)&lt;br /&gt;
| Returns an array of all the elements selected by the selector. In the second variant it first matches the base element and tries to match the selector expression on any of its children. If there are no matches both variants return an empty array.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53807</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53807"/>
		<updated>2011-10-21T02:31:19Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing for Controllers=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In rails, controller testing depends on Rails-specific structures and methods. Controller testing aims to simulate various actions of a specific controller method and test whether the results are come out as expected. It is up to you to include or not include the assertions about the view output. The test of controller and views are included in the standard rails functional testing, but some of the third party add-ons provide the separate testing of views and partials.&lt;br /&gt;
==What is Include By Functional Testing==&lt;br /&gt;
All the features included by unit testing are still present in functional testing. What is more functional testing include the following unique features:&lt;br /&gt;
•	In functional tests, you have access to the three instance variables: @controller(i.e.,the controller processing the request), @request and @response. &lt;br /&gt;
•	Rails functional tests support 5 request types: get(), post(), put(), head(), delete(). They are used to simulate each HTTP verb for the purpose of pretending to call a controller. Out of the 5 request types, the first two get() and post() are the frequently used ones.&lt;br /&gt;
•	After a request has been made by using one of the 5 methods (get, post, etc.) and processed, you will have 4 Hash objects ready for use: assign, session, cookies, and flash, each of which represents the Rails construct of the same name. Assigns allow access to any instance variable set in controller method. For example, @user in the controller method can be verified in the test by using assigns(:user). Flash is any object living in the flash. Session is any object living in session variable. As is the case with normal Hash objects, you can access the values by referencing the keys by string. You can also reference them by symbol name, except for assigns. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
flash[&amp;quot;gordon&amp;quot;]               flash[:gordon]&lt;br /&gt;
session[&amp;quot;shmession&amp;quot;]          session[:shmession]&lt;br /&gt;
cookies[&amp;quot;are_good_for_u&amp;quot;]     cookies[:are_good_for_u]&lt;br /&gt;
 &lt;br /&gt;
# Because you can't use assigns[:something] for historical reasons:&lt;br /&gt;
assigns[&amp;quot;something&amp;quot;]          assigns(:something)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
•	A series of assertions aimed at the specifics of controller and view testing. Testing the response to your request by asserting the presence of key HTML elements and their content is a useful way to test the views of your application. The assert_select assertion allows you to do this by using a simple yet powerful syntax. The following table list the series of frequently used assertion methods in functional testing.&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53801</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53801"/>
		<updated>2011-10-21T02:28:47Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Functional_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53795</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53795"/>
		<updated>2011-10-21T02:27:12Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Assertion Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53792</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53792"/>
		<updated>2011-10-21T02:26:23Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Example of Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
We can write our unit testing cases now. We will use the live question website as the example.&lt;br /&gt;
1	Ensure the username and password are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should not be saved without username and password&amp;quot; do&lt;br /&gt;
    user = User.new&lt;br /&gt;
    assert !user.save&lt;br /&gt;
    assert user.new&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
2)	Ensure the post title and content are not empty. Either one is missing, the test case will throw the error message.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;post attributes must not be empty&amp;quot; do&lt;br /&gt;
    post = Post.new&lt;br /&gt;
    assert post.invalid?&lt;br /&gt;
    assert post.errors[:title].any?&lt;br /&gt;
    assert post.errors[:content].any?&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3)	The following test case is used to test any method that extracts a set of records from the database. First, in line 3-4, it extracts the model class being tested and calls the find method on that model class, resulting in a set of instances of that model. Then in lines 5–8, each instance in the list of matching objects is tested against the block and must return true for the test to pass. Just as importantly, lines 11–14 run the block against all the instances that weren’t returned by the method and assert that the block is false for each one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def self.should_match_find_method(named_scope, *args, &amp;amp;block)&lt;br /&gt;
should &amp;quot;match a find method #{named_scope}&amp;quot; do&lt;br /&gt;
 ar_class = self.class.model_class&lt;br /&gt;
 found_objects = ar_class.send(named_scope, *args)&lt;br /&gt;
 assert !found_objects.blank?&lt;br /&gt;
 found_objects.each do |obj|&lt;br /&gt;
 assert block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 unfound_objects = ar_class.all - found_objects&lt;br /&gt;
 assert !unfound_objects.blank?&lt;br /&gt;
 unfound_objects.each do |obj|&lt;br /&gt;
 assert !block.call(obj)&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53789</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53789"/>
		<updated>2011-10-21T02:22:13Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Example of Unit Testing==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53786</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53786"/>
		<updated>2011-10-21T02:21:02Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Assertion Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_send( array, [msg] )&lt;br /&gt;
| Ensures that executing the method listed in array[1] on the object in array[0] with the parameters of array[2 and up] is true. &lt;br /&gt;
|-&lt;br /&gt;
| assert_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_nil( obj, [msg] )&lt;br /&gt;
| Ensures that obj.nil? is false.&lt;br /&gt;
|-&lt;br /&gt;
| assert_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string matches the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_no_match( regexp, string, [msg] )&lt;br /&gt;
| Ensures that a string doesn’t match the regular expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert( boolean, [msg] )&lt;br /&gt;
| Ensures that the object/expression is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_equal( A, B, [msg] )&lt;br /&gt;
| Ensures that A == B is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is true. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_not_same( A, B, [msg] )&lt;br /&gt;
| Ensures that A.equal?(B) is false. A/B is a object or an expression.&lt;br /&gt;
|-&lt;br /&gt;
| assert_in_delta( expecting, actual, delta, [msg] )&lt;br /&gt;
| Ensures that the numbers expecting and actual are within delta of each other.&lt;br /&gt;
|-&lt;br /&gt;
| assert_instance_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is of the class type.&lt;br /&gt;
|-&lt;br /&gt;
| assert_kind_of( class, obj, [msg] )&lt;br /&gt;
| Ensures that obj is or descends from class.&lt;br /&gt;
|-&lt;br /&gt;
| assert_respond_to( obj, symbol, [msg] )&lt;br /&gt;
| Ensures that obj has a method called symbol.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_operator( obj1, operator, obj2, [msg] )&lt;br /&gt;
| Ensures that obj1.operator(obj2) is true.&lt;br /&gt;
|-&lt;br /&gt;
| assert_throws( str_msg, [msg] ) { block }&lt;br /&gt;
| Ensures that the given block throws the str_msg.&lt;br /&gt;
|-&lt;br /&gt;
| assert_raise( exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block raises one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| assert_nothing_raised exception_1, exception_2, exception_n) { block }&lt;br /&gt;
| Ensures that the given block doesn’t raise one of the given exceptions.&lt;br /&gt;
|-&lt;br /&gt;
| flunk( [msg] )&lt;br /&gt;
| Ensures failure. This is useful to explicitly mark a test that isn’t finished yet.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Below are some custom assertions that Rails adds to the basic unit test.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| assert_difference(expressions, difference = 1, message = nil) {...}&lt;br /&gt;
| Test numeric difference between the return value of an expression as a result of what is evaluated in the yielded block. &lt;br /&gt;
|-&lt;br /&gt;
| assert_no_difference(expressions, message = nil, &amp;amp;block)&lt;br /&gt;
| Asserts that the numeric result of evaluating an expression is not changed before and after invoking the passed in block.&lt;br /&gt;
|-&lt;br /&gt;
| assert(record.valid?)&lt;br /&gt;
| Ensures that the passed record is valid by Active Record standards and returns any error messages if it is not.&lt;br /&gt;
|-&lt;br /&gt;
| assert_recognizes(expected_options, path, extras={}, message=nil)&lt;br /&gt;
| Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.&lt;br /&gt;
|-&lt;br /&gt;
| assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)&lt;br /&gt;
| Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.&lt;br /&gt;
|-&lt;br /&gt;
| assert_response(type, message = nil)&lt;br /&gt;
| Asserts that the response comes with a specific status code. You can specify :success to indicate 200, :redirect to indicate 300-399, :missing to indicate 404, or :error to match the 500-599 range&lt;br /&gt;
|-&lt;br /&gt;
| assert_redirected_to(options = {}, message=nil)&lt;br /&gt;
| Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such thatassert_redirected_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;) will also match the redirection ofredirect_to(:controller =&amp;gt; &amp;quot;weblog&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;) and so on.&lt;br /&gt;
|-&lt;br /&gt;
| assert_template(expected = nil, message=nil)&lt;br /&gt;
| Asserts that the request was rendered with the appropriate template file.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53768</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53768"/>
		<updated>2011-10-21T02:01:46Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Assertion Methods==&lt;br /&gt;
The following shows a complete list assertion methods for basic unit test[1]. The left side shows the assertion method names and their corresponding parameters while the right side displays the purpose of each assertion method. The parameter of [msg] is an optional string message where you could place the detailed test failure messages if you want.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Assertion&lt;br /&gt;
! Objective&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53752</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53752"/>
		<updated>2011-10-21T01:51:50Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Preparation for A Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53750</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53750"/>
		<updated>2011-10-21T01:51:15Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| rake db:migrate&lt;br /&gt;
| runs any pending migrations on the development environment and updates db/schema.rb.&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load&lt;br /&gt;
| recreates the test database from the currentdb/schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone&lt;br /&gt;
| Recreate the test database from the current environment’s database schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:clone_structure&lt;br /&gt;
| Recreate the test database from the development structure&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:load: &lt;br /&gt;
| Recreate the test database from the current schema.rb&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:prepare&lt;br /&gt;
| Check for pending migrations and load the test schema&lt;br /&gt;
|-&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
| rake db:test:purge&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53731</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53731"/>
		<updated>2011-10-21T01:45:07Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
In Rails, unit tests aims to test the models of the application. We also called it as model tests. The code you write up for model tests are placed in the directory of test/unit. What the unit testing in Rails contains is listed as follow:&lt;br /&gt;
•	Load data from fixtures before each unit test&lt;br /&gt;
•	Multiple block syntax for setup and teardown.&lt;br /&gt;
•	The test_helper.rb file, which is a important file in your application and includes the default configuration for all tests. You can put common setup and assertion methods for all tests here. It injects some additional methods into ActiveSupport::TestCase.&lt;br /&gt;
•	A series of assertion methods. Each assertion performs the examination to make sure that things are going as expected. We will show the list of assertions later.&lt;br /&gt;
&lt;br /&gt;
==What is A Good Unit Testing?==&lt;br /&gt;
Our goal for unit testing is to cover almost 100% of the code in models. We recommend writing test file for each individual model. To ensure the difference between a valid and invalid object is as expected, you need to write test to cover validations. The test-driven development advocates that any new logic should be driven by a failing test. Conversely, any new test should fail and trigger a new logic code. If you want your tests to be fewer for each method, please make sure to keep your method simpler and smaller. The following is some tips for writing a good unit testing:&lt;br /&gt;
  &lt;br /&gt;
•	Keep each of your tests to be small. &lt;br /&gt;
•	Write at least one test for some known errors. For example, without passing arguments.&lt;br /&gt;
•	Write one test for the normal case.&lt;br /&gt;
•	For the case with different branches, write one test for each branch. &lt;br /&gt;
&lt;br /&gt;
There is a tradeoff about the alignment of assertions. If you put all the assertions in single one test method, your test looks more cohesive but it does not allow the tests to run independently. If you put all the assertions in different tests, you can run the test independently but you can not observe the relationships among the tests.&lt;br /&gt;
&lt;br /&gt;
==Preparation for A Unit Testing==&lt;br /&gt;
The scaffolding in Rails will create the model, controller, view and migration. The corresponding full test suite is created at the same time. For example, when you use rails to generate scaffold of “user”, the default test stub for UserTest is created in test/unit/user_post.rb file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;test_helper&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase&lt;br /&gt;
&lt;br /&gt;
 test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'  The statement is included in all test files. It means that all the methods in this file will be available to your tests. It declare the default configuration to run the tests.&lt;br /&gt;
class UserTest &amp;lt; ActiveSupport::TestCase:&lt;br /&gt;
The UserTest class defines a test case because it inherits from ActiveSupport::TestCase.UserTest thus has all the methods available from ActiveSupport::TestCase. &lt;br /&gt;
The naming convention for test method is starting with test.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
     assert true&lt;br /&gt;
   end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The method name will be generated by replacing spaces with underscores when you run the test. So the above test method can also be written in the form of :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def test_the_truth&lt;br /&gt;
  assert true&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Before running your test, you need to use the following rake commands to make sure that the test database structure is current.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53720</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53720"/>
		<updated>2011-10-21T01:39:50Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Integration_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://weblog.rubyonrails.org/2006/3/1/new-for-rails-1-1-integration-tests&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53714</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53714"/>
		<updated>2011-10-21T01:38:39Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Unit_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53709</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53709"/>
		<updated>2011-10-21T01:37:11Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Why need Software Test for Rails Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/testing.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53707</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53707"/>
		<updated>2011-10-21T01:36:25Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* The MVC Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53706</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53706"/>
		<updated>2011-10-21T01:36:16Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* The MVC Architecture */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&amp;lt;ref&amp;gt;&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53703</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53703"/>
		<updated>2011-10-21T01:35:23Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* What is Ruby on Rails */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming. Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&amp;lt;ref&amp;gt;http://rubyonrails.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53699</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53699"/>
		<updated>2011-10-21T01:34:37Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
As we can see above, to build and run a test for rails application is fairly easy because it always provide some existing framework to do that. Also we should know that it is very important of testing the rails application. There are also some other approaches and aids for testing such as NullDB, Factory Girl, Machinist, Shoulda, and RSpec, etc.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53688</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53688"/>
		<updated>2011-10-21T01:31:27Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Testing Routes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
test &amp;quot;should route to post&amp;quot; do&lt;br /&gt;
  assert_routing '/posts/1', { :controller =&amp;gt; &amp;quot;posts&amp;quot;, :action =&amp;gt; &amp;quot;show&amp;quot;, :id =&amp;gt; &amp;quot;1&amp;quot; }&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53687</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53687"/>
		<updated>2011-10-21T01:31:11Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Testing Routes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
To set a testing route, we can write the relative codes in the controller.rb file like following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53681</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53681"/>
		<updated>2011-10-21T01:29:28Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* The Four Hashes of the Apocalypse */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53680</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53680"/>
		<updated>2011-10-21T01:28:57Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Running Your Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53679</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53679"/>
		<updated>2011-10-21T01:28:04Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Running Your Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tasks&lt;br /&gt;
! Description &lt;br /&gt;
|-&lt;br /&gt;
| rake test&lt;br /&gt;
| Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
|-&lt;br /&gt;
| rake test:benchmark&lt;br /&gt;
| Benchmark the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:functionals&lt;br /&gt;
| Runs all the functional tests from test/functional&lt;br /&gt;
|-&lt;br /&gt;
| rake test:integration&lt;br /&gt;
| Runs all the integration tests from test/integration&lt;br /&gt;
|-&lt;br /&gt;
| rake test:plugins&lt;br /&gt;
| Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
|-&lt;br /&gt;
| rake test:profile&lt;br /&gt;
| Profile the performance tests&lt;br /&gt;
|-&lt;br /&gt;
| rake test:recent&lt;br /&gt;
| Tests recent changes&lt;br /&gt;
|-&lt;br /&gt;
| rake test:uncommitted&lt;br /&gt;
| Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
|-&lt;br /&gt;
| rake test:units&lt;br /&gt;
| Runs all the unit tests from test/unit&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53647</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53647"/>
		<updated>2011-10-21T01:19:30Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53642</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53642"/>
		<updated>2011-10-21T01:18:45Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53637</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53637"/>
		<updated>2011-10-21T01:17:19Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53636</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53636"/>
		<updated>2011-10-21T01:16:30Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53632</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53632"/>
		<updated>2011-10-21T01:14:24Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53629</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53629"/>
		<updated>2011-10-21T01:12:49Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https!&lt;br /&gt;
| Allows you to mimic a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| host!&lt;br /&gt;
| Allows you to set the host name to use in the next request.&lt;br /&gt;
|-&lt;br /&gt;
| redirect?&lt;br /&gt;
| Returns true if the last request was a redirect.&lt;br /&gt;
|-&lt;br /&gt;
| follow_redirect!&lt;br /&gt;
| Follows a single redirect response.&lt;br /&gt;
|-&lt;br /&gt;
| request_via_redirect(http_method, path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| post_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| get_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| put_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| delete_via_redirect(path, [parameters], [headers])&lt;br /&gt;
| Allows you to make an HTTP DELETE request and follow any subsequent redirects.&lt;br /&gt;
|-&lt;br /&gt;
| open_session&lt;br /&gt;
| Opens a new session instance.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53576</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53576"/>
		<updated>2011-10-21T00:46:29Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53566</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53566"/>
		<updated>2011-10-21T00:45:06Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53564</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53564"/>
		<updated>2011-10-21T00:44:38Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Helper&lt;br /&gt;
! Purpose &lt;br /&gt;
|-&lt;br /&gt;
| https?&lt;br /&gt;
| Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53554</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53554"/>
		<updated>2011-10-21T00:38:55Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Category */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Unit Testing=&lt;br /&gt;
&lt;br /&gt;
=Functional Testing=&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
==Available Request Types for Functional Tests==&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
=Integration Testing=&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53547</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53547"/>
		<updated>2011-10-21T00:36:39Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53545</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53545"/>
		<updated>2011-10-21T00:34:24Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
The Low-Down on Fixtures:&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53543</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53543"/>
		<updated>2011-10-21T00:34:01Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
The Three Environments is Production, Development and Test.&lt;br /&gt;
&lt;br /&gt;
To Set Up the Environment, we may follow the next:&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
==The Low-Down on Fixtures==&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53541</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53541"/>
		<updated>2011-10-21T00:32:35Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
Three Environments&lt;br /&gt;
&lt;br /&gt;
Production&lt;br /&gt;
&lt;br /&gt;
Development&lt;br /&gt;
&lt;br /&gt;
Test&lt;br /&gt;
&lt;br /&gt;
==Set Up==&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
==The Low-Down on Fixtures==&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53539</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53539"/>
		<updated>2011-10-21T00:32:12Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
1Three Environments&lt;br /&gt;
Production&lt;br /&gt;
Development&lt;br /&gt;
Test&lt;br /&gt;
&lt;br /&gt;
==Set Up==&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
==The Low-Down on Fixtures==&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53535</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53535"/>
		<updated>2011-10-21T00:31:42Z</updated>

		<summary type="html">&lt;p&gt;Jli21: /* Basic Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
==Three Environments==&lt;br /&gt;
1.Production&lt;br /&gt;
2.Development&lt;br /&gt;
3.Test&lt;br /&gt;
&lt;br /&gt;
==Set Up==&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
==The Low-Down on Fixtures==&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53452</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4e cl</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4e_cl&amp;diff=53452"/>
		<updated>2011-10-21T00:08:38Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 4e cl&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, we introduce the testing in Ruby Rails. We give brief introduction of different kinds of tests and give the procedure about each kind.&lt;br /&gt;
&lt;br /&gt;
=What is Software Test=&lt;br /&gt;
Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test.[1] Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software implementation. Test techniques include, but are not limited to, the process of executing a program or application with the intent of finding software bugs (errors or other defects).&lt;br /&gt;
Software testing can be stated as the process of validating and verifying that a software program/application/product:&lt;br /&gt;
1.Meets the requirements that guided its design and development;&lt;br /&gt;
2.Works as expected; and&lt;br /&gt;
3.Can be implemented with the same characteristics.&lt;br /&gt;
&lt;br /&gt;
Software testing, depending on the testing method employed, can be implemented at any time in the development process. However, most of the test effort occurs after the requirements have been defined and the coding process has been completed. As such, the methodology of the test is governed by the software development methodology adopted.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Software_testing&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What is Ruby on Rails=&lt;br /&gt;
Ruby on Rails, also called Rails or RoR, is an open source web application framework for the Ruby programming language. It uses the Model-View-Controller(MVC) architecture pattern to organize the application programming。 Ruby on Rails is separated into various packages,  namely ActiveRecord, ActiveResource, ActionPack, ActiveSupport and ActionMailer. It is often installed using RubyGem, which is a package manager including with current versions of Ruby.&lt;br /&gt;
&lt;br /&gt;
=The MVC Architecture=&lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
Model-View-Controller(MVC) is a software architecture, currently considered anarchitectural pattern used in software engineering. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react.&lt;br /&gt;
The view renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes. A viewport typically has a one to one correspondence with a display surface and knows how to render to it.&lt;br /&gt;
The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and a viewport to perform actions based on that input.&lt;br /&gt;
&lt;br /&gt;
=Why need Software Test for Rails Application=&lt;br /&gt;
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.&lt;br /&gt;
Rails makes it super easy to write your tests. It starts by producing skeleton test code in the background while you are creating your models and controllers.&lt;br /&gt;
By simply running your Rails tests you can ensure your code adheres to the desired functionality even after some major code refactoring.&lt;br /&gt;
Rails tests can also simulate browser requests and thus you can test your application’s response without having to test it through your browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Basic Introduction=&lt;br /&gt;
==Set Up==&lt;br /&gt;
There is a folder named &amp;quot;test&amp;quot; which is generate when create the Rail projects. &lt;br /&gt;
To list contents of this folder&lt;br /&gt;
$ ls -F test/&lt;br /&gt;
We can see:&lt;br /&gt;
fixtures/       functional/     integration/    test_helper.rb  unit/&lt;br /&gt;
&lt;br /&gt;
==The Low-Down on Fixtures==&lt;br /&gt;
===What is a Fixture===&lt;br /&gt;
Test fixture refers to the fixed state used as a baseline for running tests in software testing. The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable.&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/Test_fixture&amp;lt;/ref&amp;gt;For good tests, you’ll need to give some thought to setting up test data. In Rails, you can handle this by defining and customizing fixtures.&lt;br /&gt;
&lt;br /&gt;
=Category=&lt;br /&gt;
==Unit Testing==&lt;br /&gt;
&lt;br /&gt;
==Functional Testing==&lt;br /&gt;
Functional testing is a type of black box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output, and internal program structure is rarely considered.&lt;br /&gt;
In Rails, testing the various actions of a single controller is called writing functional tests for that controller. Controllers handle the incoming web requests to your application and eventually respond with a rendered view.&lt;br /&gt;
===What to Include in Functional Tests===&lt;br /&gt;
1.was the web request successful?&lt;br /&gt;
2.was the user redirected to the right page?&lt;br /&gt;
3.was the user successfully authenticated?&lt;br /&gt;
4.was the correct object stored in the response template?&lt;br /&gt;
5.was the appropriate message displayed to the user in the view?&lt;br /&gt;
The get method kicks off the web request and populates the results into the response. It accepts 4 arguments:&lt;br /&gt;
•	The action of the controller you are requesting. This can be in the form of a string or a symbol.&lt;br /&gt;
•	An optional hash of request parameters to pass into the action (eg. query string parameters or post variables).&lt;br /&gt;
•	An optional hash of session variables to pass along with the request.&lt;br /&gt;
•	An optional hash of flash values.&lt;br /&gt;
&lt;br /&gt;
===Available Request Types for Functional Tests===&lt;br /&gt;
1.get&lt;br /&gt;
2.post&lt;br /&gt;
3.put&lt;br /&gt;
4.head&lt;br /&gt;
5.delete&lt;br /&gt;
===The Four Hashes of the Apocalypse===&lt;br /&gt;
1.assigns&lt;br /&gt;
2.cookies&lt;br /&gt;
3.flash&lt;br /&gt;
4.session&lt;br /&gt;
&lt;br /&gt;
== Integration Testing==&lt;br /&gt;
Integration tests are used to test the interaction among any number of controllers. They are generally used to test important work flows within your application.&lt;br /&gt;
Unlike Unit and Functional tests, integration tests have to be explicitly created under the ‘test/integration’ folder within your application. Rails provides a generator to create an integration test skeleton for you.&lt;br /&gt;
$ rails generate integration_test user_flows&lt;br /&gt;
      exists  test/integration/&lt;br /&gt;
      create  test/integration/user_flows_test.rb&lt;br /&gt;
&lt;br /&gt;
Here’s what a freshly-generated integration test looks like:&lt;br /&gt;
&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :all&lt;br /&gt;
 &lt;br /&gt;
  # Replace this with your real tests.&lt;br /&gt;
  test &amp;quot;the truth&amp;quot; do&lt;br /&gt;
    assert true&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Helper	Purpose&lt;br /&gt;
https?	Returns true if the session is mimicking a secure HTTPS request.&lt;br /&gt;
https!	Allows you to mimic a secure HTTPS request.&lt;br /&gt;
host!	Allows you to set the host name to use in the next request.&lt;br /&gt;
redirect?	Returns true if the last request was a redirect.&lt;br /&gt;
follow_redirect!	Follows a single redirect response.&lt;br /&gt;
request_via_redirect(http_method, path, [parameters], [headers])	Allows you to make an HTTP request and follow any subsequent redirects.&lt;br /&gt;
post_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP POST request and follow any subsequent redirects.&lt;br /&gt;
get_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP GET request and follow any subsequent redirects.&lt;br /&gt;
put_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP PUT request and follow any subsequent redirects.&lt;br /&gt;
delete_via_redirect(path, [parameters], [headers])	Allows you to make an HTTP DELETErequest and follow any subsequent redirects.&lt;br /&gt;
open_session	Opens a new session instance.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
require 'test_helper'&lt;br /&gt;
 &lt;br /&gt;
class UserFlowsTest &amp;lt; ActionDispatch::IntegrationTest&lt;br /&gt;
  fixtures :users&lt;br /&gt;
 &lt;br /&gt;
  test &amp;quot;login and browse site&amp;quot; do&lt;br /&gt;
    # login via https&lt;br /&gt;
    https!&lt;br /&gt;
    get &amp;quot;/login&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
 &lt;br /&gt;
    post_via_redirect &amp;quot;/login&amp;quot;, :username =&amp;gt; users(:avs).username, :password =&amp;gt; users(:avs).password&lt;br /&gt;
    assert_equal '/welcome', path&lt;br /&gt;
    assert_equal 'Welcome avs!', flash[:notice]&lt;br /&gt;
 &lt;br /&gt;
    https!(false)&lt;br /&gt;
    get &amp;quot;/posts/all&amp;quot;&lt;br /&gt;
    assert_response :success&lt;br /&gt;
    assert assigns(:products)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Running Your Tests=&lt;br /&gt;
You don’t need to set up and run your tests by hand on a test-by-test basis. Rails comes with a number of rake tasks to help in testing. The table below lists all rake tasks that come along in the default Rakefile when you initiate a Rails project.&lt;br /&gt;
Tasks	Description&lt;br /&gt;
rake test	Runs all unit, functional and integration tests. You can also simply runrake as the test target is the default.&lt;br /&gt;
rake test:benchmark	Benchmark the performance tests&lt;br /&gt;
rake test:functionals	Runs all the functional tests from test/functional&lt;br /&gt;
rake test:integration	Runs all the integration tests from test/integration&lt;br /&gt;
rake test:plugins	Run all the plugin tests from vendor/plugins/*/**/test (or specify with PLUGIN=_name_)&lt;br /&gt;
rake test:profile	Profile the performance tests&lt;br /&gt;
rake test:recent	Tests recent changes&lt;br /&gt;
rake test:uncommitted	Runs all the tests which are uncommitted. Supports Subversion and Git&lt;br /&gt;
rake test:units	Runs all the unit tests from test/unit&lt;br /&gt;
&lt;br /&gt;
Integration Test Helpers&lt;br /&gt;
=Setup and Teardown=&lt;br /&gt;
=Testing Routes=&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1a_lj&amp;diff=53451</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1a lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1a_lj&amp;diff=53451"/>
		<updated>2011-10-21T00:08:11Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 1a lj&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, several kinds of [http://en.wikipedia.org/wiki/Integrated_development_environment  Integrated Development Environments (IDEs)] for [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] are shown and their features are compared.&lt;br /&gt;
&lt;br /&gt;
=What is Ruby=    &lt;br /&gt;
[[File:Ruby.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
Ruby is a dynamic, open-source and general-purpose object-oriented programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management. In Ruby, everything is an object. Every bit of information and code can be given their own properties and actions. Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Ruby’s block are also seen as a source of great flexibility. A programmer can attach a closure to any method, describing how that method should act. Unlike many object-oriented languages, Ruby features single inheritance only, on purpose. But Ruby knows the concept of modules (called Categories in Objective-C). &amp;lt;ref&amp;gt; [http://www.ruby-lang.org/en/about/ http://www.ruby-lang.org/en/about/] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some Key Features of Ruby==   &lt;br /&gt;
&amp;lt;b&amp;gt;Interpreted&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.ntecs.de/old-hp/s-direktnet/ruby_en.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Advantage: Immediately executable (no waiting period while compiling)&lt;br /&gt;
&lt;br /&gt;
Disadvantage: Execution speed much slower than with compiler (e.g. Pascal, C++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Portable&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby is highly portable, so that one and the same Ruby program runs without changes under UNIX, Windows, DOS, Mac, BeOS and others. Of course that's only true unless using platform-specific modules, like for example some GUI's for UNIX or WinGKR (Win32 GUI Kit for Ruby).&lt;br /&gt;
&lt;br /&gt;
Advantage:less expenditure (only one program had to be managed); wider distribution of the program (because it runs on serveral platforms)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Untyped&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables in Ruby have no type, such as in Smalltalk, BASIC or Python. Variables behave as placeholders, but data is typed. In C++ or Pascal, variables are typed (e.g. int / Integer), but the data in the memory is not, that is you cannot recognize if it's a String or an Integer. In C++ or Pascal the types are checked at compile-time, whereas Ruby checks the type at runtime, so if the object understands the message (method-call) is first known after a method-call. You do not have to declare variables, because they are automatically created when you use them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Automatic memory-management (garbage collection)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You do not have to release allocated memory in Ruby (as you have to do in Pascal/C++ with dispose/free). No longer used memory, i.e. memory-frames where no variable points to, are automatically freed by the garbage collector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advanced OO-concepts and features&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-Singleton methods&lt;br /&gt;
&lt;br /&gt;
-Mix-in instead of multiple-inheritance&lt;br /&gt;
&lt;br /&gt;
-Operator overloading&lt;br /&gt;
&lt;br /&gt;
-Method-overloading (such as C++)&lt;br /&gt;
&lt;br /&gt;
-Exception handling&lt;br /&gt;
&lt;br /&gt;
-Iterators and closures&lt;br /&gt;
&lt;br /&gt;
-Meta-class&lt;br /&gt;
&lt;br /&gt;
-Build-in pattern-matching (like Perl)&lt;br /&gt;
&lt;br /&gt;
=What is an IDE=&lt;br /&gt;
An '''integrated development environment (IDE)''' (also known as '''integrated design environment''', '''integrated debugging environment''' or '''interactive development environment''') is an [http://en.wikipedia.org/wiki/Application_software application software] that provides comprehensive facilities to [http://en.wikipedia.org/wiki/Computer_programmer computer programmers] for [http://en.wikipedia.org/wiki/Software_development software development]. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Integrated_development_environment http://en.wikipedia.org/wiki/Integrated_development_environment]&amp;lt;/ref&amp;gt; An IDE normally consists of: &lt;br /&gt;
&lt;br /&gt;
* a source code editor&lt;br /&gt;
* a compiler and/or an interpreter (computing)|interpreter&lt;br /&gt;
* build automation tools&lt;br /&gt;
* a debugger&lt;br /&gt;
&lt;br /&gt;
Sometimes a version control system and various tools are integrated to simplify the construction of a GUI. Many modern IDEs also have a class browser, an object inspector, and a class hierarchy diagram, for use with object-oriented software development.&lt;br /&gt;
&lt;br /&gt;
=Popular IDEs for Ruby=&lt;br /&gt;
===&amp;lt;b&amp;gt;Eclipse&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:eclipse1.png]] [http://www.eclipse.org/downloads/ Download Here!]&lt;br /&gt;
&lt;br /&gt;
Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written mostly in Java and can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, Perl, PHP, Python, R, Ruby (including Ruby on Rails framework), Scala, Clojure, Groovy and Scheme. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Eclipse_(software) http://en.wikipedia.org/wiki/Eclipse_(software)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Aptana RadRails&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:Aptana.jpg]]  [http://www.aptana.com/products/radrails Download Here!]&lt;br /&gt;
&lt;br /&gt;
Aptana RadRails is a Rapid Application Development IDE for the Ruby on Rails framework. The goal of RadRails is to provide Ruby on Rails developers with everything they need to develop, manage, test and deploy their applications. Features include source control, code assist, refactoring, debugging, WEBrick servers, generator wizards, syntax highlighting, data tools, and much more. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/RadRails http://en.wikipedia.org/wiki/RadRails]&amp;lt;/ref&amp;gt; RadRails is now included as part of Aptana Studio 3. &amp;lt;ref&amp;gt;[http://www.aptana.com/products/radrails http://www.aptana.com/products/radrails] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;RubyMine&amp;lt;/b&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
[[File:rubymine.jpg]]  [http://www.jetbrains.com/ruby/download/index.html Download Here!]&lt;br /&gt;
&lt;br /&gt;
JetBrains RubyMine IDE provides a comprehensive Ruby code editor aware of dynamic language specifics and delivers smart coding assistance, intelligent code refactoring and code analysis capabilities. Easy project configuration, automatic Ruby Gems management, Rake support. &amp;lt;ref&amp;gt;[http://www.jetbrains.com/ruby/features/index.html http://www.jetbrains.com/ruby/features/index.html] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;NetBeans IDE&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:netbeans6.5.png]]  [http://netbeans.org/community/releases/69/ Download Here!]&lt;br /&gt;
&lt;br /&gt;
NetBeans refers to both a platform framework for Java desktop applications, and an integrated development environment (IDE) for developing with Java, JavaScript, PHP, Python, Groovy, C, C++ ,Ruby and others. NetBeans IDE is a free, open-source Integrated Development Environment for software developers. All the tools needed to create professional desktop, enterprise, web, and mobile applications with the Java platform, as well as with C/C++, PHP, JavaScript and Groovy. Noting that in NetBeans IDE 7.0, support for Ruby and Ruby on Rails is no longer available in the standard NetBeans IDE build. &amp;lt;ref&amp;gt;[http://netbeans.org/features/index.html http://netbeans.org/features/index.html]&amp;lt;/ref&amp;gt; In the following comparison we will use NetBeans IDE 6.9.&lt;br /&gt;
&lt;br /&gt;
=Comparison of Different IDEs for Ruby=  &lt;br /&gt;
&lt;br /&gt;
===Features===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
| Open Source&lt;br /&gt;
| Commercial&lt;br /&gt;
| Open Source&lt;br /&gt;
| Open Source&lt;br /&gt;
|-&lt;br /&gt;
! Language&lt;br /&gt;
| Multilingual&lt;br /&gt;
| Ruby&lt;br /&gt;
| Multilingual&lt;br /&gt;
| Ruby&lt;br /&gt;
|-&lt;br /&gt;
! Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
|-&lt;br /&gt;
! Support Multiple Processes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Plug-In&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
| API Supported&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
|-&lt;br /&gt;
! Some Uniqueness to Point out&lt;br /&gt;
| Complicated for new learner;&lt;br /&gt;
Support client plug-in&lt;br /&gt;
| Graphical Ruby Debugger;&lt;br /&gt;
Model Dependency Diagram for Ruby on Rails projects;&lt;br /&gt;
&lt;br /&gt;
Code refactorings for Ruby with knowledge about Ruby on Rails specifics;&lt;br /&gt;
&lt;br /&gt;
RSpec, Cucumber, Shoulda &amp;amp; Test::Unit test frameworks support with test-runner GUI&lt;br /&gt;
| From Version7, NetBeans IDE no longer support Ruby&lt;br /&gt;
| Fast, integrated debugger;&lt;br /&gt;
Embedded database navigator and query console;&lt;br /&gt;
&lt;br /&gt;
Snippets and wizards;&lt;br /&gt;
&lt;br /&gt;
Deep support for Ruby;&lt;br /&gt;
&lt;br /&gt;
Ruby code generation: constructors, overrides, templates, accessors&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.ruzee.com/blog/2007/02/rdt-and-radrails-keyboard-shortcuts&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring=== &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Refactor Support&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Rename&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Move&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Copy&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Change Method Signature&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Method&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Local Variable&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Constant&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Inline&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Convert Anonymous Class to Nested&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Move Type to New File&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Superclass&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Interface&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Use Supertype Where Possible&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Push Down&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Pull Up&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Module&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Parameter Object&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Indirection&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Parameter&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Encapsulate Field&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Generalize Declared Type&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Infer Generic Type Arguments&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Safe Delete&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;http://tnlessone.wordpress.com/2007/02/28/ruby-rails-ide-comparison-idea-netbeans-radrails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://netbeans.org/project_downloads/usersguide/shortcuts.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Version Control===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Subversion&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Git&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
! Perforce&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
! CVS&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
!Mercurial&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
!Clearcase&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
!SVN&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_6_aa http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_6_aa]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Editing===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Code Completion&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Type Hierarchy View&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Unavailable&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Smart Indent&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Syntax Highlighting&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Shortcuts===&lt;br /&gt;
&lt;br /&gt;
Here we choose some representative shortcuts instead of listing all.&lt;br /&gt;
&lt;br /&gt;
====Eclipse====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Alt+/&lt;br /&gt;
| Content Assist&lt;br /&gt;
|-&lt;br /&gt;
| Shift+Ctrl+K&lt;br /&gt;
| Find Previous &lt;br /&gt;
|-&lt;br /&gt;
| Alt+R&lt;br /&gt;
| Find and Replace &lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+1&lt;br /&gt;
| Quick Fix &lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Alt+H&lt;br /&gt;
| Open Call Hierarchy &lt;br /&gt;
|-&lt;br /&gt;
| Shift+Ctrl+R&lt;br /&gt;
| Open Resource &lt;br /&gt;
|-&lt;br /&gt;
|Shift+Ctrl+T&lt;br /&gt;
|Open Type &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://eclipse-tools.sourceforge.net/  http://eclipse-tools.sourceforge.net/]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Rubymine====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Alt+F1&lt;br /&gt;
| Switch between views (Project, Structure, etc.).&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Tab&lt;br /&gt;
| Switch between the tool windows and files opened in the editor.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+J&lt;br /&gt;
| Insert a live template.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Alt+J&lt;br /&gt;
| Surround with a live template. &lt;br /&gt;
|-&lt;br /&gt;
| Alt+Enter&lt;br /&gt;
| Use the suggested quick fix.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+D&lt;br /&gt;
| Duplicate the current line or selection.&lt;br /&gt;
|-&lt;br /&gt;
|Ctrl+Space&lt;br /&gt;
|Invoke code completion. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====NetBeans====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-F&lt;br /&gt;
| Search for word at insertion point&lt;br /&gt;
|-&lt;br /&gt;
| Alt-G&lt;br /&gt;
| Go to declaration&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-0&lt;br /&gt;
| Show Search Results window&lt;br /&gt;
|-&lt;br /&gt;
| Shift-F10 &lt;br /&gt;
| Open contextual menu&lt;br /&gt;
|-&lt;br /&gt;
| Alt-Enter &lt;br /&gt;
| Show suggestion/tip/hint&lt;br /&gt;
|-&lt;br /&gt;
| Alt-U, then U &lt;br /&gt;
| Convert selection to uppercase&lt;br /&gt;
|-&lt;br /&gt;
|Ctrl-Shift-1/2/3 &lt;br /&gt;
|Select in Projects/Files/Favorites&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://netbeans.org/project_downloads/usersguide/ http://netbeans.org/project_downloads/usersguide/]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Radrails====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Alt-T&lt;br /&gt;
| Jump to the test case of a model or controller and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-V&lt;br /&gt;
| Jump to the view of a controller method and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Alt-X&lt;br /&gt;
| Factor out a partial from a view. Simply select the code block you want to factor out into a separate partial an press the key combination.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-F&lt;br /&gt;
| Auto-format the selected code (Ruby only). Not that mature, yet, and seems to have problems with regular expression - currently not recommended to use.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-C&lt;br /&gt;
| Toggle comment&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
This article compares four IDEs for different features. It is hard to say which is the best for Ruby. Eclipse supports plug-ins and RadRails can be plugged into Eclipse. Netbeans provide support for other languages like Java, C++, groovy along with Ruby. RubyMine has an intelligent code editor and it is designed only for Ruby.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1a_lj&amp;diff=53450</id>
		<title>CSC/ECE 517 Fall 2011/ch1 1a lj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_1a_lj&amp;diff=53450"/>
		<updated>2011-10-21T00:07:40Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CSC/ECE 517 Fall 2010/ch1 1a lj&lt;br /&gt;
----&lt;br /&gt;
=Introduction=&lt;br /&gt;
In this Wiki, several kinds of [http://en.wikipedia.org/wiki/Integrated_development_environment  Integrated Development Environments (IDEs)] for [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby language] are shown and their features are compared.&lt;br /&gt;
&lt;br /&gt;
=What is Ruby=    &lt;br /&gt;
[[File:MVC_Diagram_3.jpg]]&lt;br /&gt;
&lt;br /&gt;
==Ruby==&lt;br /&gt;
Ruby is a dynamic, open-source and general-purpose object-oriented programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management. In Ruby, everything is an object. Every bit of information and code can be given their own properties and actions. Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Ruby’s block are also seen as a source of great flexibility. A programmer can attach a closure to any method, describing how that method should act. Unlike many object-oriented languages, Ruby features single inheritance only, on purpose. But Ruby knows the concept of modules (called Categories in Objective-C). &amp;lt;ref&amp;gt; [http://www.ruby-lang.org/en/about/ http://www.ruby-lang.org/en/about/] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some Key Features of Ruby==   &lt;br /&gt;
&amp;lt;b&amp;gt;Interpreted&amp;lt;/b&amp;gt;&amp;lt;ref&amp;gt;http://www.ntecs.de/old-hp/s-direktnet/ruby_en.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Advantage: Immediately executable (no waiting period while compiling)&lt;br /&gt;
&lt;br /&gt;
Disadvantage: Execution speed much slower than with compiler (e.g. Pascal, C++)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Portable&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ruby is highly portable, so that one and the same Ruby program runs without changes under UNIX, Windows, DOS, Mac, BeOS and others. Of course that's only true unless using platform-specific modules, like for example some GUI's for UNIX or WinGKR (Win32 GUI Kit for Ruby).&lt;br /&gt;
&lt;br /&gt;
Advantage:less expenditure (only one program had to be managed); wider distribution of the program (because it runs on serveral platforms)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Untyped&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables in Ruby have no type, such as in Smalltalk, BASIC or Python. Variables behave as placeholders, but data is typed. In C++ or Pascal, variables are typed (e.g. int / Integer), but the data in the memory is not, that is you cannot recognize if it's a String or an Integer. In C++ or Pascal the types are checked at compile-time, whereas Ruby checks the type at runtime, so if the object understands the message (method-call) is first known after a method-call. You do not have to declare variables, because they are automatically created when you use them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Automatic memory-management (garbage collection)&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You do not have to release allocated memory in Ruby (as you have to do in Pascal/C++ with dispose/free). No longer used memory, i.e. memory-frames where no variable points to, are automatically freed by the garbage collector.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Advanced OO-concepts and features&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-Singleton methods&lt;br /&gt;
&lt;br /&gt;
-Mix-in instead of multiple-inheritance&lt;br /&gt;
&lt;br /&gt;
-Operator overloading&lt;br /&gt;
&lt;br /&gt;
-Method-overloading (such as C++)&lt;br /&gt;
&lt;br /&gt;
-Exception handling&lt;br /&gt;
&lt;br /&gt;
-Iterators and closures&lt;br /&gt;
&lt;br /&gt;
-Meta-class&lt;br /&gt;
&lt;br /&gt;
-Build-in pattern-matching (like Perl)&lt;br /&gt;
&lt;br /&gt;
=What is an IDE=&lt;br /&gt;
An '''integrated development environment (IDE)''' (also known as '''integrated design environment''', '''integrated debugging environment''' or '''interactive development environment''') is an [http://en.wikipedia.org/wiki/Application_software application software] that provides comprehensive facilities to [http://en.wikipedia.org/wiki/Computer_programmer computer programmers] for [http://en.wikipedia.org/wiki/Software_development software development]. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Integrated_development_environment http://en.wikipedia.org/wiki/Integrated_development_environment]&amp;lt;/ref&amp;gt; An IDE normally consists of: &lt;br /&gt;
&lt;br /&gt;
* a source code editor&lt;br /&gt;
* a compiler and/or an interpreter (computing)|interpreter&lt;br /&gt;
* build automation tools&lt;br /&gt;
* a debugger&lt;br /&gt;
&lt;br /&gt;
Sometimes a version control system and various tools are integrated to simplify the construction of a GUI. Many modern IDEs also have a class browser, an object inspector, and a class hierarchy diagram, for use with object-oriented software development.&lt;br /&gt;
&lt;br /&gt;
=Popular IDEs for Ruby=&lt;br /&gt;
===&amp;lt;b&amp;gt;Eclipse&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:eclipse1.png]] [http://www.eclipse.org/downloads/ Download Here!]&lt;br /&gt;
&lt;br /&gt;
Eclipse is a multi-language software development environment comprising an integrated development environment (IDE) and an extensible plug-in system. It is written mostly in Java and can be used to develop applications in Java and, by means of various plug-ins, other programming languages including Ada, C, C++, COBOL, Perl, PHP, Python, R, Ruby (including Ruby on Rails framework), Scala, Clojure, Groovy and Scheme. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Eclipse_(software) http://en.wikipedia.org/wiki/Eclipse_(software)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;Aptana RadRails&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:Aptana.jpg]]  [http://www.aptana.com/products/radrails Download Here!]&lt;br /&gt;
&lt;br /&gt;
Aptana RadRails is a Rapid Application Development IDE for the Ruby on Rails framework. The goal of RadRails is to provide Ruby on Rails developers with everything they need to develop, manage, test and deploy their applications. Features include source control, code assist, refactoring, debugging, WEBrick servers, generator wizards, syntax highlighting, data tools, and much more. &amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/RadRails http://en.wikipedia.org/wiki/RadRails]&amp;lt;/ref&amp;gt; RadRails is now included as part of Aptana Studio 3. &amp;lt;ref&amp;gt;[http://www.aptana.com/products/radrails http://www.aptana.com/products/radrails] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;RubyMine&amp;lt;/b&amp;gt;===&lt;br /&gt;
&lt;br /&gt;
[[File:rubymine.jpg]]  [http://www.jetbrains.com/ruby/download/index.html Download Here!]&lt;br /&gt;
&lt;br /&gt;
JetBrains RubyMine IDE provides a comprehensive Ruby code editor aware of dynamic language specifics and delivers smart coding assistance, intelligent code refactoring and code analysis capabilities. Easy project configuration, automatic Ruby Gems management, Rake support. &amp;lt;ref&amp;gt;[http://www.jetbrains.com/ruby/features/index.html http://www.jetbrains.com/ruby/features/index.html] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;b&amp;gt;NetBeans IDE&amp;lt;/b&amp;gt;===&lt;br /&gt;
[[File:netbeans6.5.png]]  [http://netbeans.org/community/releases/69/ Download Here!]&lt;br /&gt;
&lt;br /&gt;
NetBeans refers to both a platform framework for Java desktop applications, and an integrated development environment (IDE) for developing with Java, JavaScript, PHP, Python, Groovy, C, C++ ,Ruby and others. NetBeans IDE is a free, open-source Integrated Development Environment for software developers. All the tools needed to create professional desktop, enterprise, web, and mobile applications with the Java platform, as well as with C/C++, PHP, JavaScript and Groovy. Noting that in NetBeans IDE 7.0, support for Ruby and Ruby on Rails is no longer available in the standard NetBeans IDE build. &amp;lt;ref&amp;gt;[http://netbeans.org/features/index.html http://netbeans.org/features/index.html]&amp;lt;/ref&amp;gt; In the following comparison we will use NetBeans IDE 6.9.&lt;br /&gt;
&lt;br /&gt;
=Comparison of Different IDEs for Ruby=  &lt;br /&gt;
&lt;br /&gt;
===Features===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
| Open Source&lt;br /&gt;
| Commercial&lt;br /&gt;
| Open Source&lt;br /&gt;
| Open Source&lt;br /&gt;
|-&lt;br /&gt;
! Language&lt;br /&gt;
| Multilingual&lt;br /&gt;
| Ruby&lt;br /&gt;
| Multilingual&lt;br /&gt;
| Ruby&lt;br /&gt;
|-&lt;br /&gt;
! Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
| Cross-Platform&lt;br /&gt;
|-&lt;br /&gt;
! Support Multiple Processes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Plug-In&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
| API Supported&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
| Plug-In Supported&lt;br /&gt;
|-&lt;br /&gt;
! Some Uniqueness to Point out&lt;br /&gt;
| Complicated for new learner;&lt;br /&gt;
Support client plug-in&lt;br /&gt;
| Graphical Ruby Debugger;&lt;br /&gt;
Model Dependency Diagram for Ruby on Rails projects;&lt;br /&gt;
&lt;br /&gt;
Code refactorings for Ruby with knowledge about Ruby on Rails specifics;&lt;br /&gt;
&lt;br /&gt;
RSpec, Cucumber, Shoulda &amp;amp; Test::Unit test frameworks support with test-runner GUI&lt;br /&gt;
| From Version7, NetBeans IDE no longer support Ruby&lt;br /&gt;
| Fast, integrated debugger;&lt;br /&gt;
Embedded database navigator and query console;&lt;br /&gt;
&lt;br /&gt;
Snippets and wizards;&lt;br /&gt;
&lt;br /&gt;
Deep support for Ruby;&lt;br /&gt;
&lt;br /&gt;
Ruby code generation: constructors, overrides, templates, accessors&lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-menu-refactor.htm&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://www.ruzee.com/blog/2007/02/rdt-and-radrails-keyboard-shortcuts&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Refactoring=== &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Refactor Support&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Rename&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Move&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Copy&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Change Method Signature&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Method&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Local Variable&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Constant&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Inline&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Convert Anonymous Class to Nested&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Move Type to New File&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Superclass&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Interface&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Use Supertype Where Possible&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Push Down&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Pull Up&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Extract Module&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Parameter Object&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Indirection&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Factory&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Introduce Parameter&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Encapsulate Field&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Generalize Declared Type&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Infer Generic Type Arguments&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Safe Delete&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;http://tnlessone.wordpress.com/2007/02/28/ruby-rails-ide-comparison-idea-netbeans-radrails/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref&amp;gt;http://netbeans.org/project_downloads/usersguide/shortcuts.pdf&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Version Control===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Subversion&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
! Git&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
! Perforce&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
! CVS&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
!Mercurial&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
!Clearcase&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
| Yes&lt;br /&gt;
| No&lt;br /&gt;
|-&lt;br /&gt;
!SVN&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|Yes&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_6_aa http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki1a_6_aa]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Editing===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! Eclipse&lt;br /&gt;
! RubyMine&lt;br /&gt;
! NetBeans&lt;br /&gt;
! Aptana RadRails&lt;br /&gt;
|-&lt;br /&gt;
! Code Completion&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Type Hierarchy View&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Unavailable&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Smart Indent&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|-&lt;br /&gt;
! Syntax Highlighting&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
| Available&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Shortcuts===&lt;br /&gt;
&lt;br /&gt;
Here we choose some representative shortcuts instead of listing all.&lt;br /&gt;
&lt;br /&gt;
====Eclipse====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Alt+/&lt;br /&gt;
| Content Assist&lt;br /&gt;
|-&lt;br /&gt;
| Shift+Ctrl+K&lt;br /&gt;
| Find Previous &lt;br /&gt;
|-&lt;br /&gt;
| Alt+R&lt;br /&gt;
| Find and Replace &lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+1&lt;br /&gt;
| Quick Fix &lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Alt+H&lt;br /&gt;
| Open Call Hierarchy &lt;br /&gt;
|-&lt;br /&gt;
| Shift+Ctrl+R&lt;br /&gt;
| Open Resource &lt;br /&gt;
|-&lt;br /&gt;
|Shift+Ctrl+T&lt;br /&gt;
|Open Type &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://eclipse-tools.sourceforge.net/  http://eclipse-tools.sourceforge.net/]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Rubymine====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Alt+F1&lt;br /&gt;
| Switch between views (Project, Structure, etc.).&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Tab&lt;br /&gt;
| Switch between the tool windows and files opened in the editor.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+J&lt;br /&gt;
| Insert a live template.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+Alt+J&lt;br /&gt;
| Surround with a live template. &lt;br /&gt;
|-&lt;br /&gt;
| Alt+Enter&lt;br /&gt;
| Use the suggested quick fix.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl+D&lt;br /&gt;
| Duplicate the current line or selection.&lt;br /&gt;
|-&lt;br /&gt;
|Ctrl+Space&lt;br /&gt;
|Invoke code completion. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====NetBeans====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-F&lt;br /&gt;
| Search for word at insertion point&lt;br /&gt;
|-&lt;br /&gt;
| Alt-G&lt;br /&gt;
| Go to declaration&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-0&lt;br /&gt;
| Show Search Results window&lt;br /&gt;
|-&lt;br /&gt;
| Shift-F10 &lt;br /&gt;
| Open contextual menu&lt;br /&gt;
|-&lt;br /&gt;
| Alt-Enter &lt;br /&gt;
| Show suggestion/tip/hint&lt;br /&gt;
|-&lt;br /&gt;
| Alt-U, then U &lt;br /&gt;
| Convert selection to uppercase&lt;br /&gt;
|-&lt;br /&gt;
|Ctrl-Shift-1/2/3 &lt;br /&gt;
|Select in Projects/Files/Favorites&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;ref&amp;gt;[http://netbeans.org/project_downloads/usersguide/ http://netbeans.org/project_downloads/usersguide/]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Radrails====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Shortcut&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Alt-T&lt;br /&gt;
| Jump to the test case of a model or controller and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-V&lt;br /&gt;
| Jump to the view of a controller method and vice versa.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Alt-X&lt;br /&gt;
| Factor out a partial from a view. Simply select the code block you want to factor out into a separate partial an press the key combination.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-F&lt;br /&gt;
| Auto-format the selected code (Ruby only). Not that mature, yet, and seems to have problems with regular expression - currently not recommended to use.&lt;br /&gt;
|-&lt;br /&gt;
| Ctrl-Shift-C&lt;br /&gt;
| Toggle comment&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Conclusion =&lt;br /&gt;
&lt;br /&gt;
This article compares four IDEs for different features. It is hard to say which is the best for Ruby. Eclipse supports plug-ins and RadRails can be plugged into Eclipse. Netbeans provide support for other languages like Java, C++, groovy along with Ruby. RubyMine has an intelligent code editor and it is designed only for Ruby.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:MVC_Diagram_3.jpg&amp;diff=53448</id>
		<title>File:MVC Diagram 3.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:MVC_Diagram_3.jpg&amp;diff=53448"/>
		<updated>2011-10-21T00:07:17Z</updated>

		<summary type="html">&lt;p&gt;Jli21: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jli21</name></author>
	</entry>
</feed>