<?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=Svmankar</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=Svmankar"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Svmankar"/>
	<updated>2026-05-16T07:03:15Z</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_2012/ch2a_2w13_sm&amp;diff=69156</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69156"/>
		<updated>2012-10-27T22:30:48Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Integration_testing Integration testing] is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Regression_testing Regression testing] is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults. One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other.&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Agile_software_development Agile software development] is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development] or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69155</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69155"/>
		<updated>2012-10-27T22:30:11Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Integration Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Integration_testing Integration testing] is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Regression_testing Regression testing] is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults. One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other.&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Agile_software_development Agile software development] is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development] or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69154</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69154"/>
		<updated>2012-10-27T22:29:32Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Regression Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Regression_testing Regression testing] is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults. One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other.&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Agile_software_development Agile software development] is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development] or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69153</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69153"/>
		<updated>2012-10-27T22:28:18Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Rapid Application Development */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Agile_software_development Agile software development] is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Rapid_application_development Rapid Application Development] or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69152</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69152"/>
		<updated>2012-10-27T22:27:44Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Agile Development Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Agile_software_development Agile software development] is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69151</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69151"/>
		<updated>2012-10-27T22:26:52Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Functional Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the [https://www.ruby-toolbox.com/projects/mocha mocha] gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section.&lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69150</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69150"/>
		<updated>2012-10-27T22:25:55Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression [http://en.wikipedia.org/wiki/Factorial factorial](x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69149</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69149"/>
		<updated>2012-10-27T22:24:52Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Unit Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69148</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69148"/>
		<updated>2012-10-27T22:24:19Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code.&lt;br /&gt;
&lt;br /&gt;
One cannot rely on the traditional approach and wait for the entire system to be developed before subjecting it to various tests. With the increase in the demand for faster and more accurate software, stubs provide a great mechanism for testing. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69147</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69147"/>
		<updated>2012-10-27T22:18:16Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Not Great.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69146</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69146"/>
		<updated>2012-10-27T22:17:47Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg|center]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69145</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69145"/>
		<updated>2012-10-27T22:17:32Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Eclipse */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png|center]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69144</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69144"/>
		<updated>2012-10-27T22:16:18Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Eclipse */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipse123.png]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Eclipse123.png&amp;diff=69143</id>
		<title>File:Eclipse123.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Eclipse123.png&amp;diff=69143"/>
		<updated>2012-10-27T22:15:45Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69139</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69139"/>
		<updated>2012-10-27T21:44:23Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipsestub1.png]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69138</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69138"/>
		<updated>2012-10-27T21:40:28Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Eclipse */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipsestub1.png]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Eclipsestub1.png&amp;diff=69137</id>
		<title>File:Eclipsestub1.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Eclipsestub1.png&amp;diff=69137"/>
		<updated>2012-10-27T21:39:45Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69068</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69068"/>
		<updated>2012-10-27T18:36:37Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Stubs in software development */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
===Rapid Application Development===&lt;br /&gt;
Rapid Application Development or RAD is a style of programming that focuses on having tools that allow a program to be created quickly. This is particularly useful for graphically based programs as it is easy to create a frontend which can then be used for testing the backend code. It is a software development methodology that uses minimal planning in favor of rapid prototyping. The &amp;quot;planning&amp;quot; of software developed using RAD is interleaved with writing the software itself. The lack of extensive pre-planning generally allows software to be written much faster, and makes it easier to change requirements. In such a development scenario it becomes increasingly  important to be able to write tests and successfully test the software the is being developed so that a complete product is developed in quick time. Test stubs ensure that the testing of code is not stalled in case other modules are still being developed. A programmer can immediately use test stubs and test their code and move on the the next module once its completed.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipsestub.png]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69057</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=69057"/>
		<updated>2012-10-27T18:13:25Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Stubs in software development methodologies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
&lt;br /&gt;
Unit testing with Stubs:&lt;br /&gt;
&lt;br /&gt;
In developing a huge software if we are following top down approach of development there may be some functionality which may not have been implemented. This can be overcome by implementing all the required functions. However, then we would be testing a huge chunk of code without actually testing it. This will lead to bugs and lot of time will be wasted on debugging. Consider the following example: &lt;br /&gt;
&lt;br /&gt;
Suppose we want to evaluate an expression factorial(x)/( sin(x) + tan(x) ). Assuming that we don't have library support available for calculating factorial,sin and tan of the given input we would have to write those functions. Using stubs we can write functions which would return appropriate values. Thus, assuming that factorial(x) is implemented then we can write stubs for sin and cos functions returning floating point values. We can than verify if our main function gives expected results for those values. This shows us that our main function, factorial are working correct without actually implementing sin and cos functions&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
code:&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
float y=factorial(x) / (sin(x) + tan(x) );&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
int factorial(x) &lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
	//implmentation of factorial&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float sin(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float cos(int x) &lt;br /&gt;
{&lt;br /&gt;
  return 0.3;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
&lt;br /&gt;
The idea of stub remains the same in different forms of testing. In unit testing we are dealing with working inside a module and hence we overwrite the dependent implementations by stub. This allows us to test the calling code without the actual implementation. In functional testing we will replace other modules or collaborators of a class. The client class might be interested in some service from some other class ( collaborator class ). However, again instead of implementing the actual class we will have a stub implementation. In ruby the mocha gem provides support for functional test using stubbing. This helps in avoiding overlapping test cases. We can see the use of stubs in functional testing using mocha in ruby in the programming languages section. &lt;br /&gt;
&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
&lt;br /&gt;
Eclipse provides support to create test stub methods to test the methods developed during development. We can create the junit test case on a java class. We can then select the methods in the class which we would like to test. This will automatically create test stubs to test those methods. In the figure below we are testing methods of ArrayList class&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Eclipsestub.png]]&lt;br /&gt;
&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;br /&gt;
* http://www.ibm.com/developerworks/web/library/wa-mockrails/index.html&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68508</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68508"/>
		<updated>2012-10-26T23:59:25Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or [http://en.wikipedia.org/wiki/Modular_programming modules]) on which other modules that are being tested are dependent upon. &lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an [http://en.wikipedia.org/wiki/Integration_testing Integration], if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a [http://en.wikipedia.org/wiki/Top-down_and_bottom-up_design Top Down] Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68470</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68470"/>
		<updated>2012-10-26T23:49:19Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration, if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
*[http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/ Test Stubs and Mocks]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Test_stub Test Stubs on wikipedia]&lt;br /&gt;
*[http://www.jetbrains.com/ruby/webhelp/creating-test-templates.pdf Test Stub support in RubyMine]&lt;br /&gt;
*[http://googletesting.blogspot.com/2007/04/tott-stubs-speed-up-your-unit-tests.html Advantages of Stubs]&lt;br /&gt;
*[http://sqa.fyicenter.com/FAQ/Manual-Testing/What_is_stub_Explain_in_testing_point_of_view_.html Stubs and Testing]&lt;br /&gt;
*[http://martinfowler.com/articles/mocksArentStubs.html Mocks aren't Stubs]&lt;br /&gt;
*[http://www.captaindebug.com/2011/11/regular-unit-tests-and-stubs-testing.html Testing techniques]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68421</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68421"/>
		<updated>2012-10-26T23:22:43Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration, if we don't have all the modules ready and need to test a particular module which is ready then we use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Bottom Up Integration Testing. &lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use some dummy code in the form of Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them. This piece of Dummy code is Called a Stub in a Top Down Integration. Hence Stubs are called Functions in Top Down Integration tests.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68409</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68409"/>
		<updated>2012-10-26T23:18:06Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For example, if we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
[[File:Stubs.jpg]]&lt;br /&gt;
&lt;br /&gt;
In the above figure, we can see that the Modules 2 and 3 are not yet implemented. However, if we need to test the modules 4,5 and 6 which are dependent on modules 2 and 3, we can simple use Stubs 1 and 2 in place of the modules that return the values as expected by the modules beneath them.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Stubs.jpg&amp;diff=68404</id>
		<title>File:Stubs.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Stubs.jpg&amp;diff=68404"/>
		<updated>2012-10-26T23:15:09Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68381</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68381"/>
		<updated>2012-10-26T23:00:20Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For example, if we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
We need tests that “run fast, and help us localize problems.” This can be hard to accomplish when your code accesses a database, hits another server, is time-dependent, etc. By substituting custom objects such as stubs for some of your module's dependencies, you can thoroughly test your code, increase your coverage, and still run in less than a second. You can even simulate rare scenarios like database failures and test your error handling code. In general, Stubs greatly increase the speed of running unit tests and provide a means of testing code independently.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68341</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68341"/>
		<updated>2012-10-26T22:25:04Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For example, if we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68340</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68340"/>
		<updated>2012-10-26T22:24:33Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For example, if we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68339</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68339"/>
		<updated>2012-10-26T22:23:50Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68338</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68338"/>
		<updated>2012-10-26T22:23:34Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;br /&gt;
&lt;br /&gt;
===Conclusion===&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68337</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68337"/>
		<updated>2012-10-26T22:21:37Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Agile Development Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism.&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behavior that you don’t want to take into account in this test, using a stub for this other class can simplify its behavior and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actually finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68335</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68335"/>
		<updated>2012-10-26T22:20:49Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Agile Development Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	If the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	If the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68333</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68333"/>
		<updated>2012-10-26T22:20:34Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Agile Development Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
*	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
&lt;br /&gt;
*	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
*	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68331</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68331"/>
		<updated>2012-10-26T22:19:50Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Agile Development Methodology */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68330</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68330"/>
		<updated>2012-10-26T22:18:43Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false.&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68329</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68329"/>
		<updated>2012-10-26T22:17:47Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68327</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68327"/>
		<updated>2012-10-26T22:16:16Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
[code]&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
[code]&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68325</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68325"/>
		<updated>2012-10-26T22:15:48Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
&lt;br /&gt;
[code]&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
&lt;br /&gt;
[code]&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68324</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68324"/>
		<updated>2012-10-26T22:15:07Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
[code]&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
[code]&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68322</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68322"/>
		<updated>2012-10-26T22:13:33Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
[code]&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
[code]&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
[code]&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
[/code]&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68320</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68320"/>
		<updated>2012-10-26T22:11:45Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* RubyMine */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
The most basic way to create test templates in RubyMine is to use the regular procedure of creating files in the project. This means is both available for both plain Ruby projets, and for the Rails applications, and allows creating stub tests for Test::Unit, RSpec and Test-Spec.&lt;br /&gt;
&lt;br /&gt;
For RSpec and Test-Spec, RubyMine provides a number of generators. These generators are context sensitive and become available depending on the selected location, and on the gems activated for your project. For example, ir rspec-rails is activated, the usual generators are hidden, and the list of generators includes only those specific for RSpec.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68299</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68299"/>
		<updated>2012-10-26T21:40:28Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Visual Studio */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Visual Studio is a fine IDE that provides good support for automatically generating stubs for methods. Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call. Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68298</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68298"/>
		<updated>2012-10-26T21:38:57Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* IDE support for Stubs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;br /&gt;
===Eclipse===&lt;br /&gt;
===RubyMine===&lt;br /&gt;
===Visual Studio===&lt;br /&gt;
Generate Method Stub is an IntelliSense Automatic Code Generation feature that provides an easy way to have Visual Studio create a new method declaration at the time you are writing a method call. Visual Studio infers the declaration from the call.&lt;br /&gt;
&lt;br /&gt;
Some programming styles, such as test-driven development, suggest that you should consume before you define. That way, it is easier to figure out the form of the API that you are developing. You can use IntelliSense to program in that style. Using the Generate Method Stub operation, you avoid defining everything before you consume it.&lt;br /&gt;
&lt;br /&gt;
The Generate Method Stub IntelliSense operation can also increase productivity because you do not need to move from the calling code, your present focus, to the defining code, a separate focus, in order to generate a new method. You can instead write a method call, and then invoke the Generate Method Stub operation without dividing your attention.&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68245</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68245"/>
		<updated>2012-10-26T20:45:31Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For Eg: If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration.&lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68142</id>
		<title>CSC/ECE 517 Fall 2012/ch2a 2w13 sm</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2a_2w13_sm&amp;diff=68142"/>
		<updated>2012-10-25T02:05:06Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: Created page with &amp;quot;==Introduction== Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested. Stubs are rep...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
Test stubs are programs which simulate the behaviors of software components (or modules) that are depended upon modules of the module being tested.&lt;br /&gt;
Stubs are replacements for missing components that the components being tested will call as part of the test. While doing an Integration , If we dont have all the modules get ready and Need to test a particualr module which is ready then We Use Stubs and Drivers. &lt;br /&gt;
Stubs are used in Integration testing for a Top Down Integration testing and Botton Up Integration Testing. &lt;br /&gt;
For EX : If we have Modules x,y,z . X module is ready and Need to Test it , But it calls functions from y and z.(Which are not ready)To test this particular module we can write a Small Dummy piece of code which Simulates Y and Z Which will return values that X expects. This piece of Dummy code is Called a Stub in a Top Down Integration &lt;br /&gt;
So Stubs are called Functions in Top Down Integration. &lt;br /&gt;
&lt;br /&gt;
==Stubs in different phases of testing==&lt;br /&gt;
===Unit Testing===&lt;br /&gt;
===Functional Testing===&lt;br /&gt;
===Integration Testing===&lt;br /&gt;
Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.&lt;br /&gt;
Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.&lt;br /&gt;
The top-down approach to integration testing requires the highest-level modules be test and integrated first. This allows high-level logic and data flow to be tested early in the process and it tends to minimize the need for drivers. However, the need for stubs complicates test management and low-level utilities are tested relatively late in the development cycle. Another disadvantage of top-down integration testing is its poor support for early release of limited functionality.&lt;br /&gt;
&lt;br /&gt;
===Regression Testing===&lt;br /&gt;
Regression testing is any type of software testing that seeks to uncover new software bugs, or regressions, in existing functional and non-functional areas of a system after changes, such as enhancements, patches or configuration changes, have been made to them.&lt;br /&gt;
The intent of regression testing is to ensure that a change, such as a bugfix, did not introduce new faults.[1] One of the main reasons for regression testing is to determine whether a change in one part of the software affects other parts of the software.[2]&lt;br /&gt;
Common methods of regression testing include rerunning previously run tests and checking whether program behavior has changed and whether previously fixed faults have re-emerged. Regression testing can be used to test a system efficiently by systematically selecting the appropriate minimum set of tests needed to adequately cover a particular change.&lt;br /&gt;
In Regression testing the use of test stubs is minimized as most of the system is already implemented and the main goal of the regression test is to see if there are any bugs that might have been ‘regressed’ from the previous stages of integrations. Ideally there will not be unimplemented modules by the time a system is tested for regression. However, in case of mutually exclusive modules of a system, a test stub for one of them can be used to test the regression of the other. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Stubs in software development methodologies==&lt;br /&gt;
===Agile Development Methodology===&lt;br /&gt;
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.&lt;br /&gt;
In such a development system, it recognizes that testing is not a separate phase, but an integral part of software development, along with coding. Agile testing is a software testing practice that follows the principles of agile software development. Agile testing involves all members of a cross-functional agile team, with special expertise contributed by testers, to ensure delivering the business value desired by the customer at frequent intervals, working at a sustainable pace. Specification by example, also known as acceptance test-driven development, is used to capture examples of desired and undesired behavior and guide coding.&lt;br /&gt;
In the agile testing toolkit, a stub is a piece of code that behaves in a predefined way, in order to simplify the testing process. Here are the kind of simplifications that a stub can bring:&lt;br /&gt;
•	if the code under test never returns the same value (usage of a timestamp or of a random value), a stub can be used to fix the root of the undeterminism&lt;br /&gt;
•	if the code depends on some other class that has complex behaviour that you don’t want to take into account in this test, using a stub for this other class can simplify its behaviour and clarify the intent of the test&lt;br /&gt;
•	if the code depends on some other code that is not yet written or released, it is possible to start building the rest of the code before the dependency is actualy finished.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Examples of Stubs==&lt;br /&gt;
===Java===&lt;br /&gt;
In Java, the basic technique is to implement the stub collaborators as concrete classes which only exhibit the small part of the overall behaviour of the collaborator which is needed by the class under test. As an example consider the case where a service implementation is under test. The implementation has a collaborator:&lt;br /&gt;
public class SimpleService implements Service {&lt;br /&gt;
 &lt;br /&gt;
    private Collaborator collaborator;&lt;br /&gt;
    public void setCollaborator(Collaborator collaborator) {&lt;br /&gt;
        this.collaborator = collaborator;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    // part of Service interface&lt;br /&gt;
    public boolean isActive() {&lt;br /&gt;
        return collaborator.isActive();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We could have a stub collaborator for testing as defined below:&lt;br /&gt;
public class StubCollaboratorAdapter implements Collaborator {&lt;br /&gt;
   public boolean isActive() {&lt;br /&gt;
       return false;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
Now, a test case can be written as something like this:&lt;br /&gt;
public void testActiveWhenCollaboratorIsActive() throws Exception {&lt;br /&gt;
 &lt;br /&gt;
    Service service = new SimpleService();&lt;br /&gt;
    service.setCollaborator(new StubCollaboratorAdapter() {&lt;br /&gt;
        public boolean isActive() {&lt;br /&gt;
           return true;&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
    assertTrue(service.isActive());&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===Ruby===&lt;br /&gt;
While writing stubs, one might decide to replace a whole object or simply change the results of a single method. When you're replacing a whole object, it's easy—just write the new object and replace it within your test case. Methods might be tougher in some languages, but using dynamic languages such as Ruby, stubbing is easy because you're simply redefining a method.&lt;br /&gt;
Imagine you have a user interface that prints a document. You want to test code that handles a print failure. You really don't care if the print method gets called. You just want to verify that if your code does call print, that code will handle a failed print effectively. Think of what a pseudo-code sentence would look like. &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
You can break that sentence down into two parts. The first part identifies what you want to stub. The second part defines what the stub should do.&lt;br /&gt;
Below is an example of the Mocha framework that can be used to build stubs in Ruby:&lt;br /&gt;
class Document&lt;br /&gt;
  def print&lt;br /&gt;
    # doesn't matter -- we are stubbing it out&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class View&lt;br /&gt;
  attr :document&lt;br /&gt;
&lt;br /&gt;
  def initialize(document)&lt;br /&gt;
    @document = document&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def print()&lt;br /&gt;
    if document.print&lt;br /&gt;
      puts &amp;quot;Excellent!&amp;quot;&lt;br /&gt;
      true&lt;br /&gt;
    else&lt;br /&gt;
      puts &amp;quot;Bummer.&amp;quot;&lt;br /&gt;
      false&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Test code can be written as follows:&lt;br /&gt;
require 'test/unit'&lt;br /&gt;
require 'rubygems'&lt;br /&gt;
require 'mocha'&lt;br /&gt;
require 'document'&lt;br /&gt;
&lt;br /&gt;
class ViewTest &amp;lt; Test::Unit::TestCase&lt;br /&gt;
&lt;br /&gt;
  def test_should_return_false_for_failed_print&lt;br /&gt;
    document = stub(&amp;quot;my document&amp;quot;)&lt;br /&gt;
    document.stubs(:print).returns(false)&lt;br /&gt;
&lt;br /&gt;
    ui = View.new(document)&lt;br /&gt;
    assert_equal false, ui.print&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
You can see how this works. I build a simple, named stub object with the statement stub(&amp;quot;my document&amp;quot;). Then, I define the behavior for print within the stub with the line of code document.stubs(:print).returns(false). If you look carefully, this line of code looks remarkably similar to the pseudo-code from earlier: &lt;br /&gt;
On an instance of the document object, stub the print method, returning false. &lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
&lt;br /&gt;
==IDE support for Stubs==&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=68138</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=68138"/>
		<updated>2012-10-25T01:58:17Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w26 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w11_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w15 rr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w33 pv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w20_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w14_bb]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w21_ap]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w13_sm]]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66917</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w40 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66917"/>
		<updated>2012-10-04T00:49:40Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection ]is a relatively common [http://en.wikipedia.org/wiki/Computer_programming computer programming] concept where in the program has the inherent ability to examine itself at run time. Based on its observations the program can modify it's behavior for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation. Precisely, &amp;quot;Reflection&amp;quot; can be defined as a language's ability to inspect and dynamically call [http://en.wikipedia.org/wiki/Class_%28computer_programming%29 classes], methods, attributes, etc. at runtime. More advanced uses of reflection let you list and call methods, [http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29 constructors], etc.&lt;br /&gt;
&lt;br /&gt;
Reflection is important since it lets you write programs that does not have to &amp;quot;know&amp;quot; everything at compile time, making them more dynamic, since they can be tied together at runtime. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class. Since the program need not have all the information at compile time it makes the program more dynamic. The code can be written against known interfaces, but the actual classes to be used can be instantiated using reflection from configuration files. Lots of modern frameworks uses reflection extensively for this very reason. In [http://en.wikipedia.org/wiki/Scripting_language scripting languages] like Python reflection is even more tightly integrated, since it matches more naturally with the general programming model.&lt;br /&gt;
&lt;br /&gt;
Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith&amp;lt;ref&amp;gt;[http://hdl.handle.net/1721.1/15961 Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982.]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://publications.csail.mit.edu/lcs/specpub.php?id=840 Brian C. Smith. Reflection and semantics in a procedural language. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Mass., January 1982.]&amp;lt;/ref&amp;gt; in 1992.&lt;br /&gt;
&lt;br /&gt;
In the simple illustration provided below in ruby we can see how the name of a class can be obtained from the object and how we can get the ancestor classes and modules of a particular class. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.class #=&amp;gt; Fixnum&lt;br /&gt;
&lt;br /&gt;
&amp;quot;helloworld&amp;quot;.class #=&amp;gt; String&lt;br /&gt;
&lt;br /&gt;
String.ancestors #=&amp;gt; [String, Enumerable, Comparable, Object, Kernel]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some of the common information that can be obtained from reflection are :&lt;br /&gt;
* Object type&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Superclass_%28computer_science%29#Subclasses_and_superclasses Super classes] of any class&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Method_(computer_programming) Methods]&lt;br /&gt;
* class fields&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/concepts/interface.html Interfaces]&lt;br /&gt;
&lt;br /&gt;
These are discussed in detail in the below sections.&lt;br /&gt;
Common languages that exhibit reflection to varying degrees are Ruby, Java, Smalltalk, C# and more.&lt;br /&gt;
&lt;br /&gt;
There are two basic types of reflection:&lt;br /&gt;
* Behavioral Reflection: This type of reflection changes the behaviour of the execution of the program based on observation and modification.&lt;br /&gt;
* Structural Reflection: This type of reflection deals with changing the very structure of the program such as the data structures and flow of control in the program.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Reflection is in essense a connection between the object-level (program) and meta-level (the processor). The ability of the object level to be able to observe and modify the meta-level information is the consequence of this connection. These actions can be termed as [http://en.wikipedia.org/wiki/Type_introspection introspection] (This involves the action of observing the class) and intercession (this involves the operation of modifying the behavior of the class). These actions can  implemented with the implementation of the following components:&lt;br /&gt;
&lt;br /&gt;
* Ability to create [http://en.wikipedia.org/wiki/First-class_object first class objects] ie  [http://en.wikipedia.org/wiki/Reification_(computer_science) reification]. &lt;br /&gt;
&lt;br /&gt;
* Ability to convert a string that denotes a class or a method into its corresponding    reference or invocation.&lt;br /&gt;
&lt;br /&gt;
* Ability to use and create symbolic links to methods and classes.&lt;br /&gt;
&lt;br /&gt;
==Reflection in C# ==&lt;br /&gt;
===Features===&lt;br /&gt;
In C#, Reflection uses the type system. C# is a [http://en.wikipedia.org/wiki/Strong_typing strongly-typed] language in which every variable and constant has a type. Not only this, but every expression that evaluates to a value is also associated with a type. Every method signature specifies a type for each input parameter and for the return value. A typical C# program uses the types from the class library as an addition to the user-defined types that are specific to the program's problem domain.&lt;br /&gt;
&lt;br /&gt;
C# maintains a special database called the [http://en.wikipedia.org/wiki/Metadata ‘metadata’] where a compiled C# program is usually encoded and stored. This metadata can then be used by reflection to act upon and read the required data present in it. This provides astonishing features such as accessing the members of an object or class based on their string names. This can be done by using the System.Reflection namespace provided in C#.&lt;br /&gt;
&lt;br /&gt;
As an example, the below program uses the System.Reflection namespace to access the metadata of itself. It searches for the public field with the name &amp;quot;_mynumber&amp;quot; and then acquires its value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _mynumber = 4;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    Type type = typeof(ReflectionUsage);&lt;br /&gt;
    FieldInfo info = type.GetField(&amp;quot;_mynumber&amp;quot;);&lt;br /&gt;
    object obj = type.GetValue(null);&lt;br /&gt;
    Console.WriteLine(obj);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program would then output the number ‘4’ which is the value that is assigned to the variable “_mynumber”.&lt;br /&gt;
&lt;br /&gt;
Here is how the System.Reflection class contains in C#.&lt;br /&gt;
&lt;br /&gt;
[[File:Csharp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Below are the several powerful reflection features that are provided by C#:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Field Reflection:&amp;lt;/b&amp;gt; This gives the power to scan or search the fields in your C# program by using the [http://msdn.microsoft.com/en-us/library/system.type.getfield%28v=vs.71%29.aspx GetField] or GetFields methods. Using this reflection we can load field values and then loop through those fields and display their names and values. The System.Reflection namespace provides a powerful and maintainable way to enumerate fields and properties. It can then access these fields by name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SetValue Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue%28v=vs.71%29.aspx SetValue] accesses the fields by their names. We can take a string that usually represents a target field, and then using the System.Reflection namespace methods, change the actual value of that field.&lt;br /&gt;
Below is an example that does precisely this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _myfield;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    FieldInfo info = typeof(ReflectionUsage).GetField(&amp;quot;_myfield&amp;quot;);&lt;br /&gt;
    info.SetValue(null, 2012);&lt;br /&gt;
    Console.WriteLine(_myfield);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above program would output 2012 which is the value that we set using the SetValue reflection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MethodInfo Invoke:&amp;lt;/b&amp;gt; Let us say we have the name of a method in the string format and want to invoke it. In such a case, one can use the [http://msdn.microsoft.com/en-us/library/system.type.getmethod%28v=vs.71%29.aspx GetMethod] method and then invoke the MethodInfo that can be acquired from it. The invoke method can be called to invoke method with the name specified by the string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Type Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.type.aspx Type] is one of the most important types when using reflection in C#. The Type type is used to describe data types. It stores the C# type information in a variable, property or field and can be used as an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sizeof:&amp;lt;/b&amp;gt; The [http://msdn.microsoft.com/en-us/library/eahchzkf.aspx sizeof] operator exposes information about the implementation of types in the code. It does not require the System.Reflection namespace. However, it is related to reflection in the sense that it expresses information about the program itself.&lt;br /&gt;
&lt;br /&gt;
===Advantages:===&lt;br /&gt;
&lt;br /&gt;
1. In C#, one can write code that uses for example a System.Xml.XMLDataDocument class, which loads and parses an XML document and then allows you to parse the DOM during runtime. During parsing, every time that an &amp;lt;object&amp;gt; node is scanned, a new object needs to be created using its FQN (fully qualified name). Every time a &amp;lt;property&amp;gt; node is parsed, then its parent node's property needs to be set to a newly created object. Also, every time that a &amp;lt;function&amp;gt; node is parsed, the parent object that is created must have the function, by name, called on it using the arguments that are later defined. This would allow you to create any object type that you want, and set properties and call functions for initialization, in a very recursive manner. The use of reflection would render this code to be surprisingly small because it takes advantage of recursion and the generic nature of reflection.&lt;br /&gt;
&lt;br /&gt;
2. Programs that use reflection have the ability to look inside themselves to see their own inner workings and structure. This capacity can lend them unique and powerful features that can be used to write better code.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages:===&lt;br /&gt;
&lt;br /&gt;
1. One main disadvantage of using reflection would be that reflection in general is that they can render programs that are less clear to read, harder to understand. A new person reading the code can find it hard to grasp what the code is actually doing.&lt;br /&gt;
&lt;br /&gt;
2. Another disadvantage is that it can render programs that are generally slower.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Java==&lt;br /&gt;
Reflection is a part of Java API which enables Java code to inspect and reflect Java components like class and objects during runtime. Classes in the [http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/package-summary.html java.lang.reflect] package along with [http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html java.lang.Class] and [http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Package.html java.lang.Package] take care of applications like degugger, interpreters, objects inspectors, class browsers. Important protocols such as [http://en.wikipedia.org/wiki/SOAP SOAP] and JavaBeans would not have been possible, if it weren't for Reflection. The aid a developer gets from an IDE (Integrated Development Environment) during coding is achieved by using nothing else but Reflection. Reflection is one of the advanced features of Java, it gives runtime information about the objects, classes, fields and methods in a class, interfaces, etc. The image below shows some major functions related to java reflection. &lt;br /&gt;
&lt;br /&gt;
[[File:Tjava_reflection.gif]]&lt;br /&gt;
&lt;br /&gt;
Now we will have a look at some of the important features in Java Reflection and will see how they are implemented.&lt;br /&gt;
===Features ===&lt;br /&gt;
&amp;lt;b&amp;gt;Classes: &amp;lt;/b&amp;gt;&lt;br /&gt;
The first thing any programmer would do using reflection would be to inspect Java classes at runtime. The java package java.lang.Class helps to gather all important information about the class at runtime. We can obtain class name, class modifiers, constructors, field, method, superclass, implemented interface etc. &lt;br /&gt;
&lt;br /&gt;
Before you can do any inspection on a class you need to obtain its java.lang.Class object. All types in Java including the primitive types (int, long, float etc.) including arrays have an associated Class object. If you know the name of the class at compile time you can obtain a Class object like this:&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
String className = obtainClass.getName();&lt;br /&gt;
 System.out.printf(&amp;quot;ClassName: %s\n&amp;quot;,className);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Constructors: &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Java reflection one can inspect the constructors of classes and instantiate object of that class at runtime. This is done using Java class java.lang.reflect.Constructor. The steps to do this operation are as follows:&lt;br /&gt;
1) obtaining constructor objects&lt;br /&gt;
2) get constructor parameters&lt;br /&gt;
3) Instantiating Objects using constructors&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
import java.lang.reflect.*;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
&lt;br /&gt;
public String msg;&lt;br /&gt;
&lt;br /&gt;
public DemoClass(String forMsg){&lt;br /&gt;
msg = forMsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
try{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
Constructor constructor = obtainClass.getConstructor(new Class[]{String.class});&lt;br /&gt;
DemoClass myDemo = (DemoClass)constructor.newInstance(&amp;quot;Welcome to Java Reflection&amp;quot;);&lt;br /&gt;
System.out.printf(&amp;quot;New Instance String: %s\n&amp;quot;,myDemo.msg);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch(Exception e)&lt;br /&gt;
{&lt;br /&gt;
System.err.printf(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Field: &amp;lt;/b&amp;gt;&lt;br /&gt;
	Inspecting the fields of classes and get/set them at runtime is another feature provided by Java Reflection. This is done using Java class java.lang.reflect.Field. To get/set a field value using Java reflection following are steps involved: obtaining field objects, field name, field type and getting and setting field values.&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getFields();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Methods: &amp;lt;/b&amp;gt;&lt;br /&gt;
One can also inspect the methods of class at runtime and invoke them. The class to implement this functionality is  java.lang.reflect.Method. The steps to obtain methods from a class are:&lt;br /&gt;
Obtaining Method Objects&lt;br /&gt;
Method Parameters and Return Types&lt;br /&gt;
Invoking Methods using Method object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
1) One of the major advantage of Java reflection is in debugging. While debugging one should be able to examine the private members of classes. &lt;br /&gt;
2) Also while testing one should be able to enlist all members of class along with the relationship with superclass so as to ensure that all code branches are covered.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
1) Java reflection provides access to private variables and methods, this exposes the implementation of the class. Such use of class functionalities which break the abstraction can result is portability problems in future upgrades.&lt;br /&gt;
&lt;br /&gt;
2) Reflection involves method execution which resolve at runtime, so with certain Java virtual machines which do not perform optimizations can result in performance overhead with use to Java reflection.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
Ruby is a dynamic language and one of many advantages which Ruby provides is its ability to introspect into a class or object known as reflection. What kind of introspection Ruby provides? It provides a way to inspect class objects using instance_of?, class hierarchy using ancestors, contents &amp;amp; behavior of class like which operations it supports, instance variables, etc and information on methods.&lt;br /&gt;
&lt;br /&gt;
===Dynamic binding : Making reflection possible===&lt;br /&gt;
&lt;br /&gt;
Ruby implements  [http://en.wikipedia.org/wiki/Dynamic_dispatch dynamic binding] of objects. Dynamic binding plays a very important role in [http://en.wikipedia.org/wiki/Metaprogramming meta-programming].&lt;br /&gt;
&lt;br /&gt;
In languages like C,C++; a simple assignment &amp;quot;a = b&amp;quot;, would require 'a' and 'b' to be of the same type. The assignment is interpreted as copying b into a and is implemented by copying the contents of b into the space occupied by a. Thus if 'a' had been declared as an object whose memory size is less than b's object, then object slicing takes place i.e. only that part of 'b' which fits into a's memory would be copied. This behavior might lead to unintended consequences.&lt;br /&gt;
&lt;br /&gt;
[[File:Slicing.gif]]&lt;br /&gt;
&lt;br /&gt;
But dynamic binding in Ruby ensures that the type of object stored in a variable is determined at run time and not at compile time. Thus the assignment &amp;quot;a = b&amp;quot; is interpreted as binding 'a' to the same object that 'b' is bound to. It is implemented by copying the reference stored in b into the (pointer-sized) memory cell of 'a'. Thus 'a' and 'b' point to the same object after the assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Before_binding.png]]        [[File:After_binding.png]]&lt;br /&gt;
&lt;br /&gt;
===Symbols and their usage in reflection techniques===&lt;br /&gt;
&lt;br /&gt;
====Basics====&lt;br /&gt;
[http://en.wikipedia.org/wiki/Symbol_%28programming%29 Symbols] are objects used to represent names and strings inside a Ruby [http://en.wikipedia.org/wiki/Interpreter_%28computing%29 interpreter]. They are immutable and remain unique i.e. every instance of a particular symbol is the same symbol.&lt;br /&gt;
&lt;br /&gt;
====Usage in reflection techniques====&lt;br /&gt;
Symbols are widely used in reflection to invoke methods dynamically. Reflection methods like 'respond_to', 'send' make use of symbols as a reference to other methods. Strings can also be used in place of symbols. However symbols are more efficient compared to strings in terms of memory and performance.&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
====Passing method by reference using a symbol====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Float&lt;br /&gt;
  def poly&lt;br /&gt;
    self*self*self + 2*self*self + 3*self + 4&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And we can pass poly to an integration routine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
area = integrate(:poly, 0, 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Symbols in reflection====&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-send Send] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
irb(main):015:0&amp;gt; to = [:to_s , :to_f]&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
irb(main):016:0&amp;gt; to.each{|method| puts &amp;quot;#{method} =&amp;gt; #{5.send method}&amp;quot;}&lt;br /&gt;
to_s =&amp;gt; 5&lt;br /&gt;
to_f =&amp;gt; 5.0&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-respond_to-3F respond_to] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
5.respond_to? :slice #=&amp;gt; false&lt;br /&gt;
5.respond_to? :to_f #=&amp;gt; true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj = Object.new&lt;br /&gt;
if obj.respond_to?(:program)&lt;br /&gt;
  obj.program&lt;br /&gt;
else&lt;br /&gt;
  puts &amp;quot;Sorry, the object doesn't understand the 'program' message.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===method_missing===&lt;br /&gt;
&lt;br /&gt;
Whenever a call to a method is made on an object , Ruby does a method look up. If the method is not found, Ruby calls a method named '[http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.method_missing method_missing]'. Ruby knows the existence of the 'method_missing' as all objects are instances of 'BasicObject' which includes 'method_missing'. The default behavior of BasicObject#method_missing is to respond by raising a [http://www.ruby-doc.org/core-1.9.2/NoMethodError.html NoMethodError].&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Method_overriding Overriding] 'method_missing' allows users to call methods that don't really exist. The example below illustrates overriding of 'method_missing' to the programmer's advantage. Ruby passes as parameters the name of the method called and the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
'''Example1'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Cat&lt;br /&gt;
  def mew&lt;br /&gt;
    puts &amp;quot;Meow&amp;quot;&lt;br /&gt;
  end  &lt;br /&gt;
  def method_missing(meth, *args)&lt;br /&gt;
    puts &amp;quot;Sorry, I do not #{meth}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
c = Cat.new&lt;br /&gt;
c.mew&lt;br /&gt;
&amp;gt;&amp;gt;Meow&lt;br /&gt;
c.bark&lt;br /&gt;
&amp;gt;&amp;gt; Sorry, I do not bark &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, as the method 'bark' does not exist, method_missing is called with the meth (method name as a symbol) :bark. Hence the result &amp;quot; Sorry, I do not bark &amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''Example2'''&lt;br /&gt;
Using method_missing to convert Roman numerals &amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt; to integers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Roman &lt;br /&gt;
&lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    roman_string.to_s.upcase.split(//).reverse.inject(0) do |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
        last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
      memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end   &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Evaluating Roman.xix calls the xix method of module Roman. Roman has no xix method, so 	method_missing is invoked with :xix as the argument.The id2name method of class Symbol is invoked on xix returning &amp;quot;xix&amp;quot;. The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
''' Example 3 '''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Performer&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    &amp;quot;The duck will #{name}: #{args[0]}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duck = Performer.new&lt;br /&gt;
duck.sing(&amp;quot;Quacking in the Rain&amp;quot;) # =&amp;gt; &amp;quot;The duck will sing: Quacking in the Rain&amp;quot;&lt;br /&gt;
duck.dance(&amp;quot;Swan Lake&amp;quot;) # =&amp;gt; &amp;quot;The duck will dance: Swan Lake&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Applications of Reflection==&lt;br /&gt;
*Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class. &lt;br /&gt;
&lt;br /&gt;
*Programmers who deal with a multitude of classes at the same time can use reflection to create a “serializer” that for a given class uses reflection to go through all the instance variables and processes them accordingly.&lt;br /&gt;
&lt;br /&gt;
*Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.&lt;br /&gt;
&lt;br /&gt;
*Reflection provides the ability to morph the code based on dynamic situations. This provides a sense of artificial intelligence to the program as whole.&lt;br /&gt;
&lt;br /&gt;
*Reflection can be used to debug and verify code as it provides access to the insides of a program.&lt;br /&gt;
&lt;br /&gt;
*Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absense of methods and classes when they are deprecated.&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
Ruby provides a very good reflection ability where one can introspect various properties about an object and the class it belongs to, during runtime. One can obtain the list of methods that are supported on an object by using the 'methods' reflection method on the object. In addition, the 'class' reflection method enables one to query the class that an object belongs to. Similarly, the 'superclass' method allows one to inspect all the super classes of the class that an object belongs to.&lt;br /&gt;
&lt;br /&gt;
In PHP, we have a class called as ReflectionClass which holds the class type for a particlar class. In the class row for PHP we can see that all Reflection operations can be performed on only class Reflection. So as to check if a particular instance belongs to class 'Foo', we need to first create the ReflectionClass object as shown and then call isInstance(argument) method on it. PHP also has getMethods() method which returns a list of class methods.&lt;br /&gt;
&lt;br /&gt;
In Objective C, every type we see is of type class, whether it be String, Integer or Double. So type check in Objective C can be done using method isKindOfClass. But to perform other Reflection tasks, one needs to obtain the object of class first using the object_getClass(Class_Object) method. Once this object is obtained we can then perform operations like getting method list, etc as shown in table. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Ruby&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | PHP&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Objective C&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Class&lt;br /&gt;
|Method: instance_of?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.instance_of? String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isInstance()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$class = new ReflectionClass('Foo');&lt;br /&gt;
if ($class-&amp;gt;isInstance($arg)) {&lt;br /&gt;
   echo &amp;quot;Yes&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myObject isKindOfClass:[MyObject class])&lt;br /&gt;
{&lt;br /&gt;
//do something&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Method&lt;br /&gt;
|Method: methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 list = r.methods &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::getMethods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $class = new ReflectionClass('Apple');&lt;br /&gt;
$methods = $class-&amp;gt;getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: class_copyMethodList() &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SomeClass * t = [[SomeClass alloc] init];&lt;br /&gt;
unsigned int mc = 0;&lt;br /&gt;
Method * mlist = &lt;br /&gt;
class_copyMethodList&lt;br /&gt;
(object_getClass(t), &amp;amp;mc);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Type&lt;br /&gt;
|Method: Object.class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;quot;Hello&amp;quot;.class&lt;br /&gt;
&amp;gt;&amp;gt;String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: gettype()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$data = array(1, 'foo');&lt;br /&gt;
foreach ($data as $value) {&lt;br /&gt;
    echo gettype($value), &amp;quot;\n&amp;quot;;&lt;br /&gt;
}?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myDemo isKindOfClass:[DemoClass class]])&lt;br /&gt;
{&lt;br /&gt;
    //code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | String representation of an object&lt;br /&gt;
|Method: to_s &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.to_s &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::__toString —&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$reflectionClass = &lt;br /&gt;
new ReflectionClass(MyDemoClass);&lt;br /&gt;
echo $reflectionClass-&amp;gt;__toString();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: [NSString stringWithFormat:&amp;quot;&amp;quot;]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*objString = [NSString &lt;br /&gt;
stringWithFormat:”%@”,myObject]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages and Disadvantages of reflection==&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility:&amp;lt;/b&amp;gt; Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.&lt;br /&gt;
* &amp;lt;b&amp;gt;Class browsers in IDEs:&amp;lt;/b&amp;gt; The ability to examine the members of classes makes implementation of visual aids, auto-completion and documentation easy in development tools for programmers.&lt;br /&gt;
* &amp;lt;b&amp;gt;Debugging and Test Harness:&amp;lt;/b&amp;gt; Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions. Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.&lt;br /&gt;
* &amp;lt;b&amp;gt;Correctness:&amp;lt;/b&amp;gt; Reflection improves the robustness and the correctness of a program  especially in dynamically typed languages as runtime checks can be added to check the availability of the methods or classes.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Performance Overhead:&amp;lt;/b&amp;gt; Reflection resolves types of objects and classes are dynamically at runtime, this introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.&lt;br /&gt;
* &amp;lt;b&amp;gt;Security: &amp;lt;/b&amp;gt; At run-time binding in reflection we loose the security of compile time checks and verification. It also provides access to the internals of a class or an encapsulated object like private methods and variables which makes security a major issue.&lt;br /&gt;
*&amp;lt;b&amp;gt;Portability: &amp;lt;/b&amp;gt; Another issue is of portability, over a period of time the code may change during updates and a Reflective code breaks abstraction. Such a code may change behavior during updates and may become dysfunctional. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Reading==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]&lt;br /&gt;
*[http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
*[http://tutorials.jenkov.com/java-reflection/classes.html Java Reflection]&lt;br /&gt;
*[http://www.slideshare.net/CiaranMcHale/java-reflection-explained-simply Java reflection basics]&lt;br /&gt;
*[http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation]&lt;br /&gt;
*[http://www.quora.com/Computer-Programming/How-is-reflection-useful Uses of reflection]&lt;br /&gt;
*[http://download.oracle.com/javase/tutorial/reflect/index.html Java reflection official website]&lt;br /&gt;
*[http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Ruby Documentation]&lt;br /&gt;
*[http://www.slideshare.net/MarcusDenker/behavioral-reflection Behavioral reflection]&lt;br /&gt;
*[http://csharp.net-tutorials.com/reflection/introduction/ Csharp reflection 1]&lt;br /&gt;
*[http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257/An-Introduction-to-Reflection-in-C.htm Csharp reflection 2]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66914</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w40 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66914"/>
		<updated>2012-10-04T00:49:01Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Additional Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection ]is a relatively common [http://en.wikipedia.org/wiki/Computer_programming computer programming] concept where in the program has the inherent ability to examine itself at run time. Based on its observations the program can modify it's behavior for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation. Precisely, &amp;quot;Reflection&amp;quot; can be defined as a language's ability to inspect and dynamically call [http://en.wikipedia.org/wiki/Class_%28computer_programming%29 classes], methods, attributes, etc. at runtime. More advanced uses of reflection let you list and call methods, [http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29 constructors], etc.&lt;br /&gt;
&lt;br /&gt;
Reflection is important since it lets you write programs that does not have to &amp;quot;know&amp;quot; everything at compile time, making them more dynamic, since they can be tied together at runtime. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class. Since the program need not have all the information at compile time it makes the program more dynamic. The code can be written against known interfaces, but the actual classes to be used can be instantiated using reflection from configuration files. Lots of modern frameworks uses reflection extensively for this very reason. In [http://en.wikipedia.org/wiki/Scripting_language scripting languages] like Python reflection is even more tightly integrated, since it matches more naturally with the general programming model.&lt;br /&gt;
&lt;br /&gt;
Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith&amp;lt;ref&amp;gt;[http://hdl.handle.net/1721.1/15961 Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982.]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://publications.csail.mit.edu/lcs/specpub.php?id=840 Brian C. Smith. Reflection and semantics in a procedural language. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Mass., January 1982.]&amp;lt;/ref&amp;gt; in 1992.&lt;br /&gt;
&lt;br /&gt;
In the simple illustration provided below in ruby we can see how the name of a class can be obtained from the object and how we can get the ancestor classes and modules of a particular class. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.class #=&amp;gt; Fixnum&lt;br /&gt;
&lt;br /&gt;
&amp;quot;helloworld&amp;quot;.class #=&amp;gt; String&lt;br /&gt;
&lt;br /&gt;
String.ancestors #=&amp;gt; [String, Enumerable, Comparable, Object, Kernel]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some of the common information that can be obtained from reflection are :&lt;br /&gt;
* Object type&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Superclass_%28computer_science%29#Subclasses_and_superclasses Super classes] of any class&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Method_(computer_programming) Methods]&lt;br /&gt;
* class fields&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/concepts/interface.html Interfaces]&lt;br /&gt;
&lt;br /&gt;
These are discussed in detail in the below sections.&lt;br /&gt;
Common languages that exhibit reflection to varying degrees are Ruby, Java, Smalltalk, C# and more.&lt;br /&gt;
&lt;br /&gt;
There are two basic types of reflection:&lt;br /&gt;
* Behavioral Reflection: This type of reflection changes the behaviour of the execution of the program based on observation and modification.&lt;br /&gt;
* Structural Reflection: This type of reflection deals with changing the very structure of the program such as the data structures and flow of control in the program.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Reflection is in essense a connection between the object-level (program) and meta-level (the processor). The ability of the object level to be able to observe and modify the meta-level information is the consequence of this connection. These actions can be termed as [http://en.wikipedia.org/wiki/Type_introspection introspection] (This involves the action of observing the class) and intercession (this involves the operation of modifying the behavior of the class). These actions can  implemented with the implementation of the following components:&lt;br /&gt;
&lt;br /&gt;
* Ability to create [http://en.wikipedia.org/wiki/First-class_object first class objects] ie  [http://en.wikipedia.org/wiki/Reification_(computer_science) reification]. &lt;br /&gt;
&lt;br /&gt;
* Ability to convert a string that denotes a class or a method into its corresponding    reference or invocation.&lt;br /&gt;
&lt;br /&gt;
* Ability to use and create symbolic links to methods and classes.&lt;br /&gt;
&lt;br /&gt;
==Reflection in C# ==&lt;br /&gt;
===Features===&lt;br /&gt;
In C#, Reflection uses the type system. C# is a [http://en.wikipedia.org/wiki/Strong_typing strongly-typed] language in which every variable and constant has a type. Not only this, but every expression that evaluates to a value is also associated with a type. Every method signature specifies a type for each input parameter and for the return value. A typical C# program uses the types from the class library as an addition to the user-defined types that are specific to the program's problem domain.&lt;br /&gt;
&lt;br /&gt;
C# maintains a special database called the [http://en.wikipedia.org/wiki/Metadata ‘metadata’] where a compiled C# program is usually encoded and stored. This metadata can then be used by reflection to act upon and read the required data present in it. This provides astonishing features such as accessing the members of an object or class based on their string names. This can be done by using the System.Reflection namespace provided in C#.&lt;br /&gt;
&lt;br /&gt;
As an example, the below program uses the System.Reflection namespace to access the metadata of itself. It searches for the public field with the name &amp;quot;_mynumber&amp;quot; and then acquires its value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _mynumber = 4;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    Type type = typeof(ReflectionUsage);&lt;br /&gt;
    FieldInfo info = type.GetField(&amp;quot;_mynumber&amp;quot;);&lt;br /&gt;
    object obj = type.GetValue(null);&lt;br /&gt;
    Console.WriteLine(obj);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program would then output the number ‘4’ which is the value that is assigned to the variable “_mynumber”.&lt;br /&gt;
&lt;br /&gt;
Here is how the System.Reflection class contains in C#.&lt;br /&gt;
&lt;br /&gt;
[[File:Csharp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Below are the several powerful reflection features that are provided by C#:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Field Reflection:&amp;lt;/b&amp;gt; This gives the power to scan or search the fields in your C# program by using the [http://msdn.microsoft.com/en-us/library/system.type.getfield%28v=vs.71%29.aspx GetField] or GetFields methods. Using this reflection we can load field values and then loop through those fields and display their names and values. The System.Reflection namespace provides a powerful and maintainable way to enumerate fields and properties. It can then access these fields by name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SetValue Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue%28v=vs.71%29.aspx SetValue] accesses the fields by their names. We can take a string that usually represents a target field, and then using the System.Reflection namespace methods, change the actual value of that field.&lt;br /&gt;
Below is an example that does precisely this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _myfield;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    FieldInfo info = typeof(ReflectionUsage).GetField(&amp;quot;_myfield&amp;quot;);&lt;br /&gt;
    info.SetValue(null, 2012);&lt;br /&gt;
    Console.WriteLine(_myfield);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above program would output 2012 which is the value that we set using the SetValue reflection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MethodInfo Invoke:&amp;lt;/b&amp;gt; Let us say we have the name of a method in the string format and want to invoke it. In such a case, one can use the [http://msdn.microsoft.com/en-us/library/system.type.getmethod%28v=vs.71%29.aspx GetMethod] method and then invoke the MethodInfo that can be acquired from it. The invoke method can be called to invoke method with the name specified by the string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Type Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.type.aspx Type] is one of the most important types when using reflection in C#. The Type type is used to describe data types. It stores the C# type information in a variable, property or field and can be used as an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sizeof:&amp;lt;/b&amp;gt; The [http://msdn.microsoft.com/en-us/library/eahchzkf.aspx sizeof] operator exposes information about the implementation of types in the code. It does not require the System.Reflection namespace. However, it is related to reflection in the sense that it expresses information about the program itself.&lt;br /&gt;
&lt;br /&gt;
===Advantages:===&lt;br /&gt;
&lt;br /&gt;
1. In C#, one can write code that uses for example a System.Xml.XMLDataDocument class, which loads and parses an XML document and then allows you to parse the DOM during runtime. During parsing, every time that an &amp;lt;object&amp;gt; node is scanned, a new object needs to be created using its FQN (fully qualified name). Every time a &amp;lt;property&amp;gt; node is parsed, then its parent node's property needs to be set to a newly created object. Also, every time that a &amp;lt;function&amp;gt; node is parsed, the parent object that is created must have the function, by name, called on it using the arguments that are later defined. This would allow you to create any object type that you want, and set properties and call functions for initialization, in a very recursive manner. The use of reflection would render this code to be surprisingly small because it takes advantage of recursion and the generic nature of reflection.&lt;br /&gt;
&lt;br /&gt;
2. Programs that use reflection have the ability to look inside themselves to see their own inner workings and structure. This capacity can lend them unique and powerful features that can be used to write better code.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages:===&lt;br /&gt;
&lt;br /&gt;
1. One main disadvantage of using reflection would be that reflection in general is that they can render programs that are less clear to read, harder to understand. A new person reading the code can find it hard to grasp what the code is actually doing.&lt;br /&gt;
&lt;br /&gt;
2. Another disadvantage is that it can render programs that are generally slower.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Java==&lt;br /&gt;
Reflection is a part of Java API which enables Java code to inspect and reflect Java components like class and objects during runtime. Classes in the [http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/package-summary.html java.lang.reflect] package along with [http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html java.lang.Class] and [http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Package.html java.lang.Package] take care of applications like degugger, interpreters, objects inspectors, class browsers. Important protocols such as [http://en.wikipedia.org/wiki/SOAP SOAP] and JavaBeans would not have been possible, if it weren't for Reflection. The aid a developer gets from an IDE (Integrated Development Environment) during coding is achieved by using nothing else but Reflection. Reflection is one of the advanced features of Java, it gives runtime information about the objects, classes, fields and methods in a class, interfaces, etc. The image below shows some major functions related to java reflection. &lt;br /&gt;
&lt;br /&gt;
[[File:Tjava_reflection.gif]]&lt;br /&gt;
&lt;br /&gt;
Now we will have a look at some of the important features in Java Reflection and will see how they are implemented.&lt;br /&gt;
===Features ===&lt;br /&gt;
&amp;lt;b&amp;gt;Classes: &amp;lt;/b&amp;gt;&lt;br /&gt;
The first thing any programmer would do using reflection would be to inspect Java classes at runtime. The java package java.lang.Class helps to gather all important information about the class at runtime. We can obtain class name, class modifiers, constructors, field, method, superclass, implemented interface etc. &lt;br /&gt;
&lt;br /&gt;
Before you can do any inspection on a class you need to obtain its java.lang.Class object. All types in Java including the primitive types (int, long, float etc.) including arrays have an associated Class object. If you know the name of the class at compile time you can obtain a Class object like this:&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
String className = obtainClass.getName();&lt;br /&gt;
 System.out.printf(&amp;quot;ClassName: %s\n&amp;quot;,className);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Constructors: &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Java reflection one can inspect the constructors of classes and instantiate object of that class at runtime. This is done using Java class java.lang.reflect.Constructor. The steps to do this operation are as follows:&lt;br /&gt;
1) obtaining constructor objects&lt;br /&gt;
2) get constructor parameters&lt;br /&gt;
3) Instantiating Objects using constructors&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
import java.lang.reflect.*;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
&lt;br /&gt;
public String msg;&lt;br /&gt;
&lt;br /&gt;
public DemoClass(String forMsg){&lt;br /&gt;
msg = forMsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
try{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
Constructor constructor = obtainClass.getConstructor(new Class[]{String.class});&lt;br /&gt;
DemoClass myDemo = (DemoClass)constructor.newInstance(&amp;quot;Welcome to Java Reflection&amp;quot;);&lt;br /&gt;
System.out.printf(&amp;quot;New Instance String: %s\n&amp;quot;,myDemo.msg);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch(Exception e)&lt;br /&gt;
{&lt;br /&gt;
System.err.printf(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Field: &amp;lt;/b&amp;gt;&lt;br /&gt;
	Inspecting the fields of classes and get/set them at runtime is another feature provided by Java Reflection. This is done using Java class java.lang.reflect.Field. To get/set a field value using Java reflection following are steps involved: obtaining field objects, field name, field type and getting and setting field values.&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getFields();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Methods: &amp;lt;/b&amp;gt;&lt;br /&gt;
One can also inspect the methods of class at runtime and invoke them. The class to implement this functionality is  java.lang.reflect.Method. The steps to obtain methods from a class are:&lt;br /&gt;
Obtaining Method Objects&lt;br /&gt;
Method Parameters and Return Types&lt;br /&gt;
Invoking Methods using Method object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
1) One of the major advantage of Java reflection is in debugging. While debugging one should be able to examine the private members of classes. &lt;br /&gt;
2) Also while testing one should be able to enlist all members of class along with the relationship with superclass so as to ensure that all code branches are covered.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
1) Java reflection provides access to private variables and methods, this exposes the implementation of the class. Such use of class functionalities which break the abstraction can result is portability problems in future upgrades.&lt;br /&gt;
&lt;br /&gt;
2) Reflection involves method execution which resolve at runtime, so with certain Java virtual machines which do not perform optimizations can result in performance overhead with use to Java reflection.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
Ruby is a dynamic language and one of many advantages which Ruby provides is its ability to introspect into a class or object known as reflection. What kind of introspection Ruby provides? It provides a way to inspect class objects using instance_of?, class hierarchy using ancestors, contents &amp;amp; behavior of class like which operations it supports, instance variables, etc and information on methods.&lt;br /&gt;
&lt;br /&gt;
===Dynamic binding : Making reflection possible===&lt;br /&gt;
&lt;br /&gt;
Ruby implements  [http://en.wikipedia.org/wiki/Dynamic_dispatch dynamic binding] of objects. Dynamic binding plays a very important role in [http://en.wikipedia.org/wiki/Metaprogramming meta-programming].&lt;br /&gt;
&lt;br /&gt;
In languages like C,C++; a simple assignment &amp;quot;a = b&amp;quot;, would require 'a' and 'b' to be of the same type. The assignment is interpreted as copying b into a and is implemented by copying the contents of b into the space occupied by a. Thus if 'a' had been declared as an object whose memory size is less than b's object, then object slicing takes place i.e. only that part of 'b' which fits into a's memory would be copied. This behavior might lead to unintended consequences.&lt;br /&gt;
&lt;br /&gt;
[[File:Slicing.gif]]&lt;br /&gt;
&lt;br /&gt;
But dynamic binding in Ruby ensures that the type of object stored in a variable is determined at run time and not at compile time. Thus the assignment &amp;quot;a = b&amp;quot; is interpreted as binding 'a' to the same object that 'b' is bound to. It is implemented by copying the reference stored in b into the (pointer-sized) memory cell of 'a'. Thus 'a' and 'b' point to the same object after the assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Before_binding.png]]        [[File:After_binding.png]]&lt;br /&gt;
&lt;br /&gt;
===Symbols and their usage in reflection techniques===&lt;br /&gt;
&lt;br /&gt;
====Basics====&lt;br /&gt;
[http://en.wikipedia.org/wiki/Symbol_%28programming%29 Symbols] are objects used to represent names and strings inside a Ruby [http://en.wikipedia.org/wiki/Interpreter_%28computing%29 interpreter]. They are immutable and remain unique i.e. every instance of a particular symbol is the same symbol.&lt;br /&gt;
&lt;br /&gt;
====Usage in reflection techniques====&lt;br /&gt;
Symbols are widely used in reflection to invoke methods dynamically. Reflection methods like 'respond_to', 'send' make use of symbols as a reference to other methods. Strings can also be used in place of symbols. However symbols are more efficient compared to strings in terms of memory and performance.&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
====Passing method by reference using a symbol====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Float&lt;br /&gt;
  def poly&lt;br /&gt;
    self*self*self + 2*self*self + 3*self + 4&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And we can pass poly to an integration routine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
area = integrate(:poly, 0, 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Symbols in reflection====&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-send Send] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
irb(main):015:0&amp;gt; to = [:to_s , :to_f]&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
irb(main):016:0&amp;gt; to.each{|method| puts &amp;quot;#{method} =&amp;gt; #{5.send method}&amp;quot;}&lt;br /&gt;
to_s =&amp;gt; 5&lt;br /&gt;
to_f =&amp;gt; 5.0&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-respond_to-3F respond_to] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
5.respond_to? :slice #=&amp;gt; false&lt;br /&gt;
5.respond_to? :to_f #=&amp;gt; true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj = Object.new&lt;br /&gt;
if obj.respond_to?(:program)&lt;br /&gt;
  obj.program&lt;br /&gt;
else&lt;br /&gt;
  puts &amp;quot;Sorry, the object doesn't understand the 'program' message.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===method_missing===&lt;br /&gt;
&lt;br /&gt;
Whenever a call to a method is made on an object , Ruby does a method look up. If the method is not found, Ruby calls a method named '[http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.method_missing method_missing]'. Ruby knows the existence of the 'method_missing' as all objects are instances of 'BasicObject' which includes 'method_missing'. The default behavior of BasicObject#method_missing is to respond by raising a [http://www.ruby-doc.org/core-1.9.2/NoMethodError.html NoMethodError].&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Method_overriding Overriding] 'method_missing' allows users to call methods that don't really exist. The example below illustrates overriding of 'method_missing' to the programmer's advantage. Ruby passes as parameters the name of the method called and the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
'''Example1'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Cat&lt;br /&gt;
  def mew&lt;br /&gt;
    puts &amp;quot;Meow&amp;quot;&lt;br /&gt;
  end  &lt;br /&gt;
  def method_missing(meth, *args)&lt;br /&gt;
    puts &amp;quot;Sorry, I do not #{meth}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
c = Cat.new&lt;br /&gt;
c.mew&lt;br /&gt;
&amp;gt;&amp;gt;Meow&lt;br /&gt;
c.bark&lt;br /&gt;
&amp;gt;&amp;gt; Sorry, I do not bark &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, as the method 'bark' does not exist, method_missing is called with the meth (method name as a symbol) :bark. Hence the result &amp;quot; Sorry, I do not bark &amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''Example2'''&lt;br /&gt;
Using method_missing to convert Roman numerals &amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt; to integers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Roman &lt;br /&gt;
&lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    roman_string.to_s.upcase.split(//).reverse.inject(0) do |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
        last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
      memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end   &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Evaluating Roman.xix calls the xix method of module Roman. Roman has no xix method, so 	method_missing is invoked with :xix as the argument.The id2name method of class Symbol is invoked on xix returning &amp;quot;xix&amp;quot;. The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
''' Example 3 '''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Performer&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    &amp;quot;The duck will #{name}: #{args[0]}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duck = Performer.new&lt;br /&gt;
duck.sing(&amp;quot;Quacking in the Rain&amp;quot;) # =&amp;gt; &amp;quot;The duck will sing: Quacking in the Rain&amp;quot;&lt;br /&gt;
duck.dance(&amp;quot;Swan Lake&amp;quot;) # =&amp;gt; &amp;quot;The duck will dance: Swan Lake&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Applications of Reflection==&lt;br /&gt;
*Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class. &lt;br /&gt;
&lt;br /&gt;
*Programmers who deal with a multitude of classes at the same time can use reflection to create a “serializer” that for a given class uses reflection to go through all the instance variables and processes them accordingly.&lt;br /&gt;
&lt;br /&gt;
*Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.&lt;br /&gt;
&lt;br /&gt;
*Reflection provides the ability to morph the code based on dynamic situations. This provides a sense of artificial intelligence to the program as whole.&lt;br /&gt;
&lt;br /&gt;
*Reflection can be used to debug and verify code as it provides access to the insides of a program.&lt;br /&gt;
&lt;br /&gt;
*Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absense of methods and classes when they are deprecated.&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
Ruby provides a very good reflection ability where one can introspect various properties about an object and the class it belongs to, during runtime. One can obtain the list of methods that are supported on an object by using the 'methods' reflection method on the object. In addition, the 'class' reflection method enables one to query the class that an object belongs to. Similarly, the 'superclass' method allows one to inspect all the super classes of the class that an object belongs to.&lt;br /&gt;
&lt;br /&gt;
In PHP, we have a class called as ReflectionClass which holds the class type for a particlar class. In the class row for PHP we can see that all Reflection operations can be performed on only class Reflection. So as to check if a particular instance belongs to class 'Foo', we need to first create the ReflectionClass object as shown and then call isInstance(argument) method on it. PHP also has getMethods() method which returns a list of class methods.&lt;br /&gt;
&lt;br /&gt;
In Objective C, every type we see is of type class, whether it be String, Integer or Double. So type check in Objective C can be done using method isKindOfClass. But to perform other Reflection tasks, one needs to obtain the object of class first using the object_getClass(Class_Object) method. Once this object is obtained we can then perform operations like getting method list, etc as shown in table. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Ruby&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | PHP&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Objective C&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Class&lt;br /&gt;
|Method: instance_of?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.instance_of? String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isInstance()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$class = new ReflectionClass('Foo');&lt;br /&gt;
if ($class-&amp;gt;isInstance($arg)) {&lt;br /&gt;
   echo &amp;quot;Yes&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myObject isKindOfClass:[MyObject class])&lt;br /&gt;
{&lt;br /&gt;
//do something&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Method&lt;br /&gt;
|Method: methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 list = r.methods &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::getMethods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $class = new ReflectionClass('Apple');&lt;br /&gt;
$methods = $class-&amp;gt;getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: class_copyMethodList() &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SomeClass * t = [[SomeClass alloc] init];&lt;br /&gt;
unsigned int mc = 0;&lt;br /&gt;
Method * mlist = &lt;br /&gt;
class_copyMethodList&lt;br /&gt;
(object_getClass(t), &amp;amp;mc);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Type&lt;br /&gt;
|Method: Object.class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;quot;Hello&amp;quot;.class&lt;br /&gt;
&amp;gt;&amp;gt;String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: gettype()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$data = array(1, 'foo');&lt;br /&gt;
foreach ($data as $value) {&lt;br /&gt;
    echo gettype($value), &amp;quot;\n&amp;quot;;&lt;br /&gt;
}?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myDemo isKindOfClass:[DemoClass class]])&lt;br /&gt;
{&lt;br /&gt;
    //code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | String representation of an object&lt;br /&gt;
|Method: to_s &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.to_s &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::__toString —&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$reflectionClass = &lt;br /&gt;
new ReflectionClass(MyDemoClass);&lt;br /&gt;
echo $reflectionClass-&amp;gt;__toString();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: [NSString stringWithFormat:&amp;quot;&amp;quot;]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*objString = [NSString &lt;br /&gt;
stringWithFormat:”%@”,myObject]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages and Disadvantages of reflection==&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility:&amp;lt;/b&amp;gt; Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.&lt;br /&gt;
* &amp;lt;b&amp;gt;Class browsers in IDEs:&amp;lt;/b&amp;gt; The ability to examine the members of classes makes implementation of visual aids, auto-completion and documentation easy in development tools for programmers.&lt;br /&gt;
* &amp;lt;b&amp;gt;Debugging and Test Harness:&amp;lt;/b&amp;gt; Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions. Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.&lt;br /&gt;
* &amp;lt;b&amp;gt;Correctness:&amp;lt;/b&amp;gt; Reflection improves the robustness and the correctness of a program  especially in dynamically typed languages as runtime checks can be added to check the availability of the methods or classes.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Performance Overhead:&amp;lt;/b&amp;gt; Reflection resolves types of objects and classes are dynamically at runtime, this introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.&lt;br /&gt;
* &amp;lt;b&amp;gt;Security: &amp;lt;/b&amp;gt; At run-time binding in reflection we loose the security of compile time checks and verification. It also provides access to the internals of a class or an encapsulated object like private methods and variables which makes security a major issue.&lt;br /&gt;
*&amp;lt;b&amp;gt;Portability: &amp;lt;/b&amp;gt; Another issue is of portability, over a period of time the code may change during updates and a Reflective code breaks abstraction. Such a code may change behavior during updates and may become dysfunctional. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Reading==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]&lt;br /&gt;
*[http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
*[http://tutorials.jenkov.com/java-reflection/classes.html Java Reflection]&lt;br /&gt;
*[http://www.slideshare.net/CiaranMcHale/java-reflection-explained-simply Java reflection basics]&lt;br /&gt;
*[http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation]&lt;br /&gt;
*[http://www.quora.com/Computer-Programming/How-is-reflection-useful Uses of reflection]&lt;br /&gt;
*[http://download.oracle.com/javase/tutorial/reflect/index.html Java reflection official website]&lt;br /&gt;
*[http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Ruby Documentation]&lt;br /&gt;
*[http://www.slideshare.net/MarcusDenker/behavioral-reflection Behavioral reflection]&lt;br /&gt;
*[http://csharp.net-tutorials.com/reflection/introduction/]&lt;br /&gt;
*[http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257/An-Introduction-to-Reflection-in-C.htm]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66538</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w40 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66538"/>
		<updated>2012-10-03T22:05:58Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Reflection in Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection ]is a relatively common [http://en.wikipedia.org/wiki/Computer_programming computer programming] concept where in the program has the inherent ability to examine itself at run time. Based on its observations the program can modify it's behavior for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation. Precisely, &amp;quot;Reflection&amp;quot; can be defined as a language's ability to inspect and dynamically call [http://en.wikipedia.org/wiki/Class_%28computer_programming%29 classes], methods, attributes, etc. at runtime. More advanced uses of reflection let you list and call methods, [http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29 constructors], etc.&lt;br /&gt;
&lt;br /&gt;
Reflection is important since it lets you write programs that does not have to &amp;quot;know&amp;quot; everything at compile time, making them more dynamic, since they can be tied together at runtime. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class. Since the program need not have all the information at compile time it makes the program more dynamic. The code can be written against known interfaces, but the actual classes to be used can be instantiated using reflection from configuration files. Lots of modern frameworks uses reflection extensively for this very reason. In [http://en.wikipedia.org/wiki/Scripting_language scripting languages] like Python reflection is even more tightly integrated, since it matches more naturally with the general programming model.&lt;br /&gt;
&lt;br /&gt;
Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith&amp;lt;ref&amp;gt;[http://hdl.handle.net/1721.1/15961 Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982.]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://publications.csail.mit.edu/lcs/specpub.php?id=840 Brian C. Smith. Reflection and semantics in a procedural language. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Mass., January 1982.]&amp;lt;/ref&amp;gt; in 1992.&lt;br /&gt;
&lt;br /&gt;
In the simple illustration provided below in ruby we can see how the name of a class can be obtained from the object and how we can get the ancestor classes and modules of a particular class. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.class #=&amp;gt; Fixnum&lt;br /&gt;
&lt;br /&gt;
&amp;quot;helloworld&amp;quot;.class #=&amp;gt; String&lt;br /&gt;
&lt;br /&gt;
String.ancestors #=&amp;gt; [String, Enumerable, Comparable, Object, Kernel]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some of the common information that can be obtained from reflection are :&lt;br /&gt;
* Object type&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Superclass_%28computer_science%29#Subclasses_and_superclasses Super classes] of any class&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Method_(computer_programming) Methods]&lt;br /&gt;
* class fields&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/concepts/interface.html Interfaces]&lt;br /&gt;
&lt;br /&gt;
These are discussed in detail in the below sections.&lt;br /&gt;
Common languages that exhibit reflection to varying degrees are Ruby, Java, Smalltalk, C# and more.&lt;br /&gt;
&lt;br /&gt;
There are two basic types of reflection:&lt;br /&gt;
* Behavioral Reflection: This type of reflection changes the behaviour of the execution of the program based on observation and modification.&lt;br /&gt;
* Structural Reflection: This type of reflection deals with changing the very structure of the program such as the data structures and flow of control in the program.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Reflection is in essense a connection between the object-level (program) and meta-level (the processor). The ability of the object level to be able to observe and modify the meta-level information is the consequence of this connection. These actions can be termed as [http://en.wikipedia.org/wiki/Type_introspection introspection] (This involves the action of observing the class) and intercession (this involves the operation of modifying the behavior of the class). These actions can  implemented with the implementation of the following components:&lt;br /&gt;
&lt;br /&gt;
* Ability to create [http://en.wikipedia.org/wiki/First-class_object first class objects] ie  [http://en.wikipedia.org/wiki/Reification_(computer_science) reification]. &lt;br /&gt;
&lt;br /&gt;
* Ability to convert a string that denotes a class or a method into its corresponding    reference or invocation.&lt;br /&gt;
&lt;br /&gt;
* Ability to use and create symbolic links to methods and classes.&lt;br /&gt;
&lt;br /&gt;
==Reflection in C# ==&lt;br /&gt;
===Features===&lt;br /&gt;
In C#, Reflection uses the type system. C# is a [http://en.wikipedia.org/wiki/Strong_typing strongly-typed] language in which every variable and constant has a type. Not only this, but every expression that evaluates to a value is also associated with a type. Every method signature specifies a type for each input parameter and for the return value. A typical C# program uses the types from the class library as an addition to the user-defined types that are specific to the program's problem domain.&lt;br /&gt;
&lt;br /&gt;
C# maintains a special database called the [http://en.wikipedia.org/wiki/Metadata ‘metadata’] where a compiled C# program is usually encoded and stored. This metadata can then be used by reflection to act upon and read the required data present in it. This provides astonishing features such as accessing the members of an object or class based on their string names. This can be done by using the System.Reflection namespace provided in C#.&lt;br /&gt;
&lt;br /&gt;
As an example, the below program uses the System.Reflection namespace to access the metadata of itself. It searches for the public field with the name &amp;quot;_mynumber&amp;quot; and then acquires its value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _mynumber = 4;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    Type type = typeof(ReflectionUsage);&lt;br /&gt;
    FieldInfo info = type.GetField(&amp;quot;_mynumber&amp;quot;);&lt;br /&gt;
    object obj = type.GetValue(null);&lt;br /&gt;
    Console.WriteLine(obj);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program would then output the number ‘4’ which is the value that is assigned to the variable “_mynumber”.&lt;br /&gt;
&lt;br /&gt;
Here is how the System.Reflection class contains in C#.&lt;br /&gt;
&lt;br /&gt;
[[File:Csharp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Below are the several powerful reflection features that are provided by C#:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Field Reflection:&amp;lt;/b&amp;gt; This gives the power to scan or search the fields in your C# program by using the [http://msdn.microsoft.com/en-us/library/system.type.getfield%28v=vs.71%29.aspx GetField] or GetFields methods. Using this reflection we can load field values and then loop through those fields and display their names and values. The System.Reflection namespace provides a powerful and maintainable way to enumerate fields and properties. It can then access these fields by name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SetValue Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue%28v=vs.71%29.aspx SetValue] accesses the fields by their names. We can take a string that usually represents a target field, and then using the System.Reflection namespace methods, change the actual value of that field.&lt;br /&gt;
Below is an example that does precisely this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _myfield;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    FieldInfo info = typeof(ReflectionUsage).GetField(&amp;quot;_myfield&amp;quot;);&lt;br /&gt;
    info.SetValue(null, 2012);&lt;br /&gt;
    Console.WriteLine(_myfield);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above program would output 2012 which is the value that we set using the SetValue reflection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MethodInfo Invoke:&amp;lt;/b&amp;gt; Let us say we have the name of a method in the string format and want to invoke it. In such a case, one can use the [http://msdn.microsoft.com/en-us/library/system.type.getmethod%28v=vs.71%29.aspx GetMethod] method and then invoke the MethodInfo that can be acquired from it. The invoke method can be called to invoke method with the name specified by the string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Type Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.type.aspx Type] is one of the most important types when using reflection in C#. The Type type is used to describe data types. It stores the C# type information in a variable, property or field and can be used as an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sizeof:&amp;lt;/b&amp;gt; The [http://msdn.microsoft.com/en-us/library/eahchzkf.aspx sizeof] operator exposes information about the implementation of types in the code. It does not require the System.Reflection namespace. However, it is related to reflection in the sense that it expresses information about the program itself.&lt;br /&gt;
&lt;br /&gt;
===Advantages:===&lt;br /&gt;
&lt;br /&gt;
1. In C#, one can write code that uses for example a System.Xml.XMLDataDocument class, which loads and parses an XML document and then allows you to parse the DOM during runtime. During parsing, every time that an &amp;lt;object&amp;gt; node is scanned, a new object needs to be created using its FQN (fully qualified name). Every time a &amp;lt;property&amp;gt; node is parsed, then its parent node's property needs to be set to a newly created object. Also, every time that a &amp;lt;function&amp;gt; node is parsed, the parent object that is created must have the function, by name, called on it using the arguments that are later defined. This would allow you to create any object type that you want, and set properties and call functions for initialization, in a very recursive manner. The use of reflection would render this code to be surprisingly small because it takes advantage of recursion and the generic nature of reflection.&lt;br /&gt;
&lt;br /&gt;
2. Programs that use reflection have the ability to look inside themselves to see their own inner workings and structure. This capacity can lend them unique and powerful features that can be used to write better code.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages:===&lt;br /&gt;
&lt;br /&gt;
1. One main disadvantage of using reflection would be that reflection in general is that they can render programs that are less clear to read, harder to understand. A new person reading the code can find it hard to grasp what the code is actually doing.&lt;br /&gt;
&lt;br /&gt;
2. Another disadvantage is that it can render programs that are generally slower.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Java==&lt;br /&gt;
Reflection is a part of Java API which enables Java code to inspect and reflect Java components like class and objects during runtime. Classes in the [http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/package-summary.html java.lang.reflect] package along with [http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Class.html java.lang.Class] and [http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Package.html java.lang.Package] take care of applications like degugger, interpreters, objects inspectors, class browsers. Important protocols such as [http://en.wikipedia.org/wiki/SOAP SOAP] and JavaBeans would not have been possible, if it weren't for Reflection. The aid a developer gets from an IDE (Integrated Development Environment) during coding is achieved by using nothing else but Reflection. Reflection is one of the advanced features of Java, it gives runtime information about the objects, classes, fields and methods in a class, interfaces, etc. The image below shows some major functions related to java reflection. &lt;br /&gt;
&lt;br /&gt;
[[File:Tjava_reflection.gif]]&lt;br /&gt;
&lt;br /&gt;
Now we will have a look at some of the important features in Java Reflection and will see how they are implemented.&lt;br /&gt;
===Features ===&lt;br /&gt;
&amp;lt;b&amp;gt;Classes: &amp;lt;/b&amp;gt;&lt;br /&gt;
The first thing any programmer would do using reflection would be to inspect Java classes at runtime. The java package java.lang.Class helps to gather all important information about the class at runtime. We can obtain class name, class modifiers, constructors, field, method, superclass, implemented interface etc. &lt;br /&gt;
&lt;br /&gt;
Before you can do any inspection on a class you need to obtain its java.lang.Class object. All types in Java including the primitive types (int, long, float etc.) including arrays have an associated Class object. If you know the name of the class at compile time you can obtain a Class object like this:&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
String className = obtainClass.getName();&lt;br /&gt;
 System.out.printf(&amp;quot;ClassName: %s\n&amp;quot;,className);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Constructors: &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Java reflection one can inspect the constructors of classes and instantiate object of that class at runtime. This is done using Java class java.lang.reflect.Constructor. The steps to do this operation are as follows:&lt;br /&gt;
1) obtaining constructor objects&lt;br /&gt;
2) get constructor parameters&lt;br /&gt;
3) Instantiating Objects using constructors&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
import java.lang.reflect.*;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
&lt;br /&gt;
public String msg;&lt;br /&gt;
&lt;br /&gt;
public DemoClass(String forMsg){&lt;br /&gt;
msg = forMsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
try{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
Constructor constructor = obtainClass.getConstructor(new Class[]{String.class});&lt;br /&gt;
DemoClass myDemo = (DemoClass)constructor.newInstance(&amp;quot;Welcome to Java Reflection&amp;quot;);&lt;br /&gt;
System.out.printf(&amp;quot;New Instance String: %s\n&amp;quot;,myDemo.msg);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch(Exception e)&lt;br /&gt;
{&lt;br /&gt;
System.err.printf(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Field: &amp;lt;/b&amp;gt;&lt;br /&gt;
	Inspecting the fields of classes and get/set them at runtime is another feature provided by Java Reflection. This is done using Java class java.lang.reflect.Field. To get/set a field value using Java reflection following are steps involved: obtaining field objects, field name, field type and getting and setting field values.&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getFields();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Methods: &amp;lt;/b&amp;gt;&lt;br /&gt;
One can also inspect the methods of class at runtime and invoke them. The class to implement this functionality is  java.lang.reflect.Method. The steps to obtain methods from a class are:&lt;br /&gt;
Obtaining Method Objects&lt;br /&gt;
Method Parameters and Return Types&lt;br /&gt;
Invoking Methods using Method object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
1) One of the major advantage of Java reflection is in debugging. While debugging one should be able to examine the private members of classes. &lt;br /&gt;
2) Also while testing one should be able to enlist all members of class along with the relationship with superclass so as to ensure that all code branches are covered.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
1) Java reflection provides access to private variables and methods, this exposes the implementation of the class. Such use of class functionalities which break the abstraction can result is portability problems in future upgrades.&lt;br /&gt;
&lt;br /&gt;
2) Reflection involves method execution which resolve at runtime, so with certain Java virtual machines which do not perform optimizations can result in performance overhead with use to Java reflection.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
Ruby is a dynamic language and one of many advantages which Ruby provides is its ability to introspect into a class or object known as reflection. What kind of introspection Ruby provides? It provides a way to inspect class objects using instance_of?, class hierarchy using ancestors, contents &amp;amp; behavior of class like which operations it supports, instance variables, etc and information on methods.&lt;br /&gt;
&lt;br /&gt;
===Dynamic binding : Making reflection possible===&lt;br /&gt;
&lt;br /&gt;
Ruby implements  [http://en.wikipedia.org/wiki/Dynamic_dispatch dynamic binding] of objects. Dynamic binding plays a very important role in [http://en.wikipedia.org/wiki/Metaprogramming meta-programming].&lt;br /&gt;
&lt;br /&gt;
In languages like C,C++; a simple assignment &amp;quot;a = b&amp;quot;, would require 'a' and 'b' to be of the same type. The assignment is interpreted as copying b into a and is implemented by copying the contents of b into the space occupied by a. Thus if 'a' had been declared as an object whose memory size is less than b's object, then object slicing takes place i.e. only that part of 'b' which fits into a's memory would be copied. This behavior might lead to unintended consequences.&lt;br /&gt;
&lt;br /&gt;
[[File:Slicing.gif]]&lt;br /&gt;
&lt;br /&gt;
But dynamic binding in Ruby ensures that the type of object stored in a variable is determined at run time and not at compile time. Thus the assignment &amp;quot;a = b&amp;quot; is interpreted as binding 'a' to the same object that 'b' is bound to. It is implemented by copying the reference stored in b into the (pointer-sized) memory cell of 'a'. Thus 'a' and 'b' point to the same object after the assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Before_binding.png]]        [[File:After_binding.png]]&lt;br /&gt;
&lt;br /&gt;
===Symbols and their usage in reflection techniques===&lt;br /&gt;
&lt;br /&gt;
====Basics====&lt;br /&gt;
[http://en.wikipedia.org/wiki/Symbol_%28programming%29 Symbols] are objects used to represent names and strings inside a Ruby [http://en.wikipedia.org/wiki/Interpreter_%28computing%29 interpreter]. They are immutable and remain unique i.e. every instance of a particular symbol is the same symbol.&lt;br /&gt;
&lt;br /&gt;
====Usage in reflection techniques====&lt;br /&gt;
Symbols are widely used in reflection to invoke methods dynamically. Reflection methods like 'respond_to', 'send' make use of symbols as a reference to other methods. Strings can also be used in place of symbols. However symbols are more efficient compared to strings in terms of memory and performance.&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
====Passing method by reference using a symbol====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Float&lt;br /&gt;
  def poly&lt;br /&gt;
    self*self*self + 2*self*self + 3*self + 4&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And we can pass poly to an integration routine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
area = integrate(:poly, 0, 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Symbols in reflection====&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-send Send] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
irb(main):015:0&amp;gt; to = [:to_s , :to_f]&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
irb(main):016:0&amp;gt; to.each{|method| puts &amp;quot;#{method} =&amp;gt; #{5.send method}&amp;quot;}&lt;br /&gt;
to_s =&amp;gt; 5&lt;br /&gt;
to_f =&amp;gt; 5.0&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-respond_to-3F respond_to] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
5.respond_to? :slice #=&amp;gt; false&lt;br /&gt;
5.respond_to? :to_f #=&amp;gt; true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj = Object.new&lt;br /&gt;
if obj.respond_to?(:program)&lt;br /&gt;
  obj.program&lt;br /&gt;
else&lt;br /&gt;
  puts &amp;quot;Sorry, the object doesn't understand the 'program' message.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===method_missing===&lt;br /&gt;
&lt;br /&gt;
Whenever a call to a method is made on an object , Ruby does a method look up. If the method is not found, Ruby calls a method named '[http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.method_missing method_missing]'. Ruby knows the existence of the 'method_missing' as all objects are instances of 'BasicObject' which includes 'method_missing'. The default behavior of BasicObject#method_missing is to respond by raising a [http://www.ruby-doc.org/core-1.9.2/NoMethodError.html NoMethodError].&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Method_overriding Overriding] 'method_missing' allows users to call methods that don't really exist. The example below illustrates overriding of 'method_missing' to the programmer's advantage. Ruby passes as parameters the name of the method called and the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
'''Example1'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Cat&lt;br /&gt;
  def mew&lt;br /&gt;
    puts &amp;quot;Meow&amp;quot;&lt;br /&gt;
  end  &lt;br /&gt;
  def method_missing(meth, *args)&lt;br /&gt;
    puts &amp;quot;Sorry, I do not #{meth}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
c = Cat.new&lt;br /&gt;
c.mew&lt;br /&gt;
&amp;gt;&amp;gt;Meow&lt;br /&gt;
c.bark&lt;br /&gt;
&amp;gt;&amp;gt; Sorry, I do not bark &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, as the method 'bark' does not exist, method_missing is called with the meth (method name as a symbol) :bark. Hence the result &amp;quot; Sorry, I do not bark &amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''Example2'''&lt;br /&gt;
Using method_missing to convert Roman numerals &amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt; to integers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Roman &lt;br /&gt;
&lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    roman_string.to_s.upcase.split(//).reverse.inject(0) do |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
        last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
      memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end   &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Evaluating Roman.xix calls the xix method of module Roman. Roman has no xix method, so 	method_missing is invoked with :xix as the argument.The id2name method of class Symbol is invoked on xix returning &amp;quot;xix&amp;quot;. The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
''' Example 3 '''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Performer&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    &amp;quot;The duck will #{name}: #{args[0]}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duck = Performer.new&lt;br /&gt;
duck.sing(&amp;quot;Quacking in the Rain&amp;quot;) # =&amp;gt; &amp;quot;The duck will sing: Quacking in the Rain&amp;quot;&lt;br /&gt;
duck.dance(&amp;quot;Swan Lake&amp;quot;) # =&amp;gt; &amp;quot;The duck will dance: Swan Lake&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Applications of Reflection==&lt;br /&gt;
*Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class. &lt;br /&gt;
&lt;br /&gt;
*Programmers who deal with a multitude of classes at the same time can use reflection to create a “serializer” that for a given class uses reflection to go through all the instance variables and processes them accordingly.&lt;br /&gt;
&lt;br /&gt;
*Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.&lt;br /&gt;
&lt;br /&gt;
*Reflection provides the ability to morph the code based on dynamic situations. This provides a sense of artificial intelligence to the program as whole.&lt;br /&gt;
&lt;br /&gt;
*Reflection can be used to debug and verify code as it provides access to the insides of a program.&lt;br /&gt;
&lt;br /&gt;
*Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absense of methods and classes when they are deprecated.&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
Ruby provides a very good reflection ability where one can introspect various properties about an object and the class it belongs to, during runtime. One can obtain the list of methods that are supported on an object by using the 'methods' reflection method on the object. In addition, the 'class' reflection method enables one to query the class that an object belongs to. Similarly, the 'superclass' method allows one to inspect all the super classes of the class that an object belongs to.&lt;br /&gt;
&lt;br /&gt;
In PHP, we have a class called as ReflectionClass which holds the class type for a particlar class. In the class row for PHP we can see that all Reflection operations can be performed on only class Reflection. So as to check if a particular instance belongs to class 'Foo', we need to first create the ReflectionClass object as shown and then call isInstance(argument) method on it. PHP also has getMethods() method which returns a list of class methods.&lt;br /&gt;
&lt;br /&gt;
In Objective C, every type we see is of type class, whether it be String, Integer or Double. So type check in Objective C can be done using method isKindOfClass. But to perform other Reflection tasks, one needs to obtain the object of class first using the object_getClass(Class_Object) method. Once this object is obtained we can then perform operations like getting method list, etc as shown in table. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Ruby&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | PHP&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Objective C&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Class&lt;br /&gt;
|Method: instance_of?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.instance_of? String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isInstance()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$class = new ReflectionClass('Foo');&lt;br /&gt;
if ($class-&amp;gt;isInstance($arg)) {&lt;br /&gt;
   echo &amp;quot;Yes&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myObject isKindOfClass:[MyObject class])&lt;br /&gt;
{&lt;br /&gt;
//do something&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Method&lt;br /&gt;
|Method: methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 list = r.methods &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::getMethods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $class = new ReflectionClass('Apple');&lt;br /&gt;
$methods = $class-&amp;gt;getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: class_copyMethodList() &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SomeClass * t = [[SomeClass alloc] init];&lt;br /&gt;
unsigned int mc = 0;&lt;br /&gt;
Method * mlist = &lt;br /&gt;
class_copyMethodList&lt;br /&gt;
(object_getClass(t), &amp;amp;mc);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Type&lt;br /&gt;
|Method: Object.class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;quot;Hello&amp;quot;.class&lt;br /&gt;
&amp;gt;&amp;gt;String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: gettype()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$data = array(1, 'foo');&lt;br /&gt;
foreach ($data as $value) {&lt;br /&gt;
    echo gettype($value), &amp;quot;\n&amp;quot;;&lt;br /&gt;
}?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myDemo isKindOfClass:[DemoClass class]])&lt;br /&gt;
{&lt;br /&gt;
    //code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | String representation of an object&lt;br /&gt;
|Method: to_s &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.to_s &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::__toString —&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$reflectionClass = &lt;br /&gt;
new ReflectionClass(MyDemoClass);&lt;br /&gt;
echo $reflectionClass-&amp;gt;__toString();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: [NSString stringWithFormat:&amp;quot;&amp;quot;]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*objString = [NSString &lt;br /&gt;
stringWithFormat:”%@”,myObject]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages and Disadvantages of reflection==&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility:&amp;lt;/b&amp;gt; Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.&lt;br /&gt;
* &amp;lt;b&amp;gt;Class browsers in IDEs:&amp;lt;/b&amp;gt; The ability to examine the members of classes makes implementation of visual aids, auto-completion and documentation easy in development tools for programmers.&lt;br /&gt;
* &amp;lt;b&amp;gt;Debugging and Test Harness:&amp;lt;/b&amp;gt; Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions. Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.&lt;br /&gt;
* &amp;lt;b&amp;gt;Correctness:&amp;lt;/b&amp;gt; Reflection improves the robustness and the correctness of a program  especially in dynamically typed languages as runtime checks can be added to check the availability of the methods or classes.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Performance Overhead:&amp;lt;/b&amp;gt; Reflection resolves types of objects and classes are dynamically at runtime, this introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.&lt;br /&gt;
* &amp;lt;b&amp;gt;Security: &amp;lt;/b&amp;gt; At run-time binding in reflection we loose the security of compile time checks and verification. It also provides access to the internals of a class or an encapsulated object like private methods and variables which makes security a major issue.&lt;br /&gt;
*&amp;lt;b&amp;gt;Portability: &amp;lt;/b&amp;gt; Another issue is of portability, over a period of time the code may change during updates and a Reflective code breaks abstraction. Such a code may change behavior during updates and may become dysfunctional. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Reading==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]&lt;br /&gt;
*[http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
*[http://tutorials.jenkov.com/java-reflection/classes.html Java Reflection]&lt;br /&gt;
*[http://www.slideshare.net/CiaranMcHale/java-reflection-explained-simply Java reflection basics]&lt;br /&gt;
*[http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation]&lt;br /&gt;
*[http://www.quora.com/Computer-Programming/How-is-reflection-useful Uses of reflection]&lt;br /&gt;
*[http://download.oracle.com/javase/tutorial/reflect/index.html Java reflection official website]&lt;br /&gt;
*[http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Ruby Documentation]&lt;br /&gt;
*[http://www.slideshare.net/MarcusDenker/behavioral-reflection Behavioral reflection]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66536</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w40 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66536"/>
		<updated>2012-10-03T22:02:38Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection ]is a relatively common [http://en.wikipedia.org/wiki/Computer_programming computer programming] concept where in the program has the inherent ability to examine itself at run time. Based on its observations the program can modify it's behavior for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation. Precisely, &amp;quot;Reflection&amp;quot; can be defined as a language's ability to inspect and dynamically call [http://en.wikipedia.org/wiki/Class_%28computer_programming%29 classes], methods, attributes, etc. at runtime. More advanced uses of reflection let you list and call methods, [http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29 constructors], etc.&lt;br /&gt;
&lt;br /&gt;
Reflection is important since it lets you write programs that does not have to &amp;quot;know&amp;quot; everything at compile time, making them more dynamic, since they can be tied together at runtime. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class. Since the program need not have all the information at compile time it makes the program more dynamic. The code can be written against known interfaces, but the actual classes to be used can be instantiated using reflection from configuration files. Lots of modern frameworks uses reflection extensively for this very reason. In [http://en.wikipedia.org/wiki/Scripting_language scripting languages] like Python reflection is even more tightly integrated, since it matches more naturally with the general programming model.&lt;br /&gt;
&lt;br /&gt;
Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith&amp;lt;ref&amp;gt;[http://hdl.handle.net/1721.1/15961 Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982.]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://publications.csail.mit.edu/lcs/specpub.php?id=840 Brian C. Smith. Reflection and semantics in a procedural language. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Mass., January 1982.]&amp;lt;/ref&amp;gt; in 1992.&lt;br /&gt;
&lt;br /&gt;
In the simple illustration provided below in ruby we can see how the name of a class can be obtained from the object and how we can get the ancestor classes and modules of a particular class. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.class #=&amp;gt; Fixnum&lt;br /&gt;
&lt;br /&gt;
&amp;quot;helloworld&amp;quot;.class #=&amp;gt; String&lt;br /&gt;
&lt;br /&gt;
String.ancestors #=&amp;gt; [String, Enumerable, Comparable, Object, Kernel]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some of the common information that can be obtained from reflection are :&lt;br /&gt;
* Object type&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Superclass_%28computer_science%29#Subclasses_and_superclasses Super classes] of any class&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Method_(computer_programming) Methods]&lt;br /&gt;
* class fields&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/concepts/interface.html Interfaces]&lt;br /&gt;
&lt;br /&gt;
These are discussed in detail in the below sections.&lt;br /&gt;
Common languages that exhibit reflection to varying degrees are Ruby, Java, Smalltalk, C# and more.&lt;br /&gt;
&lt;br /&gt;
There are two basic types of reflection:&lt;br /&gt;
* Behavioral Reflection: This type of reflection changes the behaviour of the execution of the program based on observation and modification.&lt;br /&gt;
* Structural Reflection: This type of reflection deals with changing the very structure of the program such as the data structures and flow of control in the program.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Reflection is in essense a connection between the object-level (program) and meta-level (the processor). The ability of the object level to be able to observe and modify the meta-level information is the consequence of this connection. These actions can be termed as [http://en.wikipedia.org/wiki/Type_introspection introspection] (This involves the action of observing the class) and intercession (this involves the operation of modifying the behavior of the class). These actions can  implemented with the implementation of the following components:&lt;br /&gt;
&lt;br /&gt;
* Ability to create [http://en.wikipedia.org/wiki/First-class_object first class objects] ie  [http://en.wikipedia.org/wiki/Reification_(computer_science) reification]. &lt;br /&gt;
&lt;br /&gt;
* Ability to convert a string that denotes a class or a method into its corresponding    reference or invocation.&lt;br /&gt;
&lt;br /&gt;
* Ability to use and create symbolic links to methods and classes.&lt;br /&gt;
&lt;br /&gt;
==Reflection in C# ==&lt;br /&gt;
===Features===&lt;br /&gt;
In C#, Reflection uses the type system. C# is a [http://en.wikipedia.org/wiki/Strong_typing strongly-typed] language in which every variable and constant has a type. Not only this, but every expression that evaluates to a value is also associated with a type. Every method signature specifies a type for each input parameter and for the return value. A typical C# program uses the types from the class library as an addition to the user-defined types that are specific to the program's problem domain.&lt;br /&gt;
&lt;br /&gt;
C# maintains a special database called the [http://en.wikipedia.org/wiki/Metadata ‘metadata’] where a compiled C# program is usually encoded and stored. This metadata can then be used by reflection to act upon and read the required data present in it. This provides astonishing features such as accessing the members of an object or class based on their string names. This can be done by using the System.Reflection namespace provided in C#.&lt;br /&gt;
&lt;br /&gt;
As an example, the below program uses the System.Reflection namespace to access the metadata of itself. It searches for the public field with the name &amp;quot;_mynumber&amp;quot; and then acquires its value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _mynumber = 4;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    Type type = typeof(ReflectionUsage);&lt;br /&gt;
    FieldInfo info = type.GetField(&amp;quot;_mynumber&amp;quot;);&lt;br /&gt;
    object obj = type.GetValue(null);&lt;br /&gt;
    Console.WriteLine(obj);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program would then output the number ‘4’ which is the value that is assigned to the variable “_mynumber”.&lt;br /&gt;
&lt;br /&gt;
Here is how the System.Reflection class contains in C#.&lt;br /&gt;
&lt;br /&gt;
[[File:Csharp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Below are the several powerful reflection features that are provided by C#:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Field Reflection:&amp;lt;/b&amp;gt; This gives the power to scan or search the fields in your C# program by using the [http://msdn.microsoft.com/en-us/library/system.type.getfield%28v=vs.71%29.aspx GetField] or GetFields methods. Using this reflection we can load field values and then loop through those fields and display their names and values. The System.Reflection namespace provides a powerful and maintainable way to enumerate fields and properties. It can then access these fields by name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SetValue Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue%28v=vs.71%29.aspx SetValue] accesses the fields by their names. We can take a string that usually represents a target field, and then using the System.Reflection namespace methods, change the actual value of that field.&lt;br /&gt;
Below is an example that does precisely this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _myfield;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    FieldInfo info = typeof(ReflectionUsage).GetField(&amp;quot;_myfield&amp;quot;);&lt;br /&gt;
    info.SetValue(null, 2012);&lt;br /&gt;
    Console.WriteLine(_myfield);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above program would output 2012 which is the value that we set using the SetValue reflection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MethodInfo Invoke:&amp;lt;/b&amp;gt; Let us say we have the name of a method in the string format and want to invoke it. In such a case, one can use the [http://msdn.microsoft.com/en-us/library/system.type.getmethod%28v=vs.71%29.aspx GetMethod] method and then invoke the MethodInfo that can be acquired from it. The invoke method can be called to invoke method with the name specified by the string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Type Reflection:&amp;lt;/b&amp;gt; [http://msdn.microsoft.com/en-us/library/system.type.aspx Type] is one of the most important types when using reflection in C#. The Type type is used to describe data types. It stores the C# type information in a variable, property or field and can be used as an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sizeof:&amp;lt;/b&amp;gt; The [http://msdn.microsoft.com/en-us/library/eahchzkf.aspx sizeof] operator exposes information about the implementation of types in the code. It does not require the System.Reflection namespace. However, it is related to reflection in the sense that it expresses information about the program itself.&lt;br /&gt;
&lt;br /&gt;
===Advantages:===&lt;br /&gt;
&lt;br /&gt;
1. In C#, one can write code that uses for example a System.Xml.XMLDataDocument class, which loads and parses an XML document and then allows you to parse the DOM during runtime. During parsing, every time that an &amp;lt;object&amp;gt; node is scanned, a new object needs to be created using its FQN (fully qualified name). Every time a &amp;lt;property&amp;gt; node is parsed, then its parent node's property needs to be set to a newly created object. Also, every time that a &amp;lt;function&amp;gt; node is parsed, the parent object that is created must have the function, by name, called on it using the arguments that are later defined. This would allow you to create any object type that you want, and set properties and call functions for initialization, in a very recursive manner. The use of reflection would render this code to be surprisingly small because it takes advantage of recursion and the generic nature of reflection.&lt;br /&gt;
&lt;br /&gt;
2. Programs that use reflection have the ability to look inside themselves to see their own inner workings and structure. This capacity can lend them unique and powerful features that can be used to write better code.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages:===&lt;br /&gt;
&lt;br /&gt;
1. One main disadvantage of using reflection would be that reflection in general is that they can render programs that are less clear to read, harder to understand. A new person reading the code can find it hard to grasp what the code is actually doing.&lt;br /&gt;
&lt;br /&gt;
2. Another disadvantage is that it can render programs that are generally slower.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Java==&lt;br /&gt;
Reflection is a part of Java API which enables Java code to inspect and reflect Java components like class and objects during runtime. Classes in the java.lang.reflect package along with java.lang.Class and java.lang.Package take care of applications like degugger, interpreters, objects inspectors, class browsers. Important protocols such as SOAP and JavaBeans would not have been possible, if it weren't for Reflection. The aid a developer gets from an IDE during coding is achieved by using nothing else but Reflection. Reflection is one of the advanced features of Java, it gives runtime information about the objects, classes, fields and methods in a class, interfaces, etc. The image below shows some major functions related to java reflection. &lt;br /&gt;
&lt;br /&gt;
[[File:Tjava_reflection.gif]]&lt;br /&gt;
&lt;br /&gt;
Now we will have a look at some of the important features in Java Reflection and will see how they are implemented.&lt;br /&gt;
===Features ===&lt;br /&gt;
&amp;lt;b&amp;gt;Classes: &amp;lt;/b&amp;gt;&lt;br /&gt;
The first thing any programmer would do using reflection would be to inspect Java classes at runtime. The java package java.lang.Class helps to gather all important information about the class at runtime. We can obtain class name, class modifiers, constructors, field, method, superclass, implemented interface etc. &lt;br /&gt;
&lt;br /&gt;
Before you can do any inspection on a class you need to obtain its java.lang.Class object. All types in Java including the primitive types (int, long, float etc.) including arrays have an associated Class object. If you know the name of the class at compile time you can obtain a Class object like this:&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
String className = obtainClass.getName();&lt;br /&gt;
 System.out.printf(&amp;quot;ClassName: %s\n&amp;quot;,className);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Constructors: &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Java reflection one can inspect the constructors of classes and instantiate object of that class at runtime. This is done using Java class java.lang.reflect.Constructor. The steps to do this operation are as follows:&lt;br /&gt;
1) obtaining constructor objects&lt;br /&gt;
2) get constructor parameters&lt;br /&gt;
3) Instantiating Objects using constructors&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
import java.lang.reflect.*;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
&lt;br /&gt;
public String msg;&lt;br /&gt;
&lt;br /&gt;
public DemoClass(String forMsg){&lt;br /&gt;
msg = forMsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
try{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
Constructor constructor = obtainClass.getConstructor(new Class[]{String.class});&lt;br /&gt;
DemoClass myDemo = (DemoClass)constructor.newInstance(&amp;quot;Welcome to Java Reflection&amp;quot;);&lt;br /&gt;
System.out.printf(&amp;quot;New Instance String: %s\n&amp;quot;,myDemo.msg);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch(Exception e)&lt;br /&gt;
{&lt;br /&gt;
System.err.printf(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Field: &amp;lt;/b&amp;gt;&lt;br /&gt;
	Inspecting the fields of classes and get/set them at runtime is another feature provided by Java Reflection. This is done using Java class java.lang.reflect.Field. To get/set a field value using Java reflection following are steps involved: obtaining field objects, field name, field type and getting and setting field values.&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getFields();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Methods: &amp;lt;/b&amp;gt;&lt;br /&gt;
One can also inspect the methods of class at runtime and invoke them. The class to implement this functionality is  java.lang.reflect.Method. The steps to obtain methods from a class are:&lt;br /&gt;
Obtaining Method Objects&lt;br /&gt;
Method Parameters and Return Types&lt;br /&gt;
Invoking Methods using Method object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
1) One of the major advantage of Java reflection is in debugging. While debugging one should be able to examine the private members of classes. &lt;br /&gt;
2) Also while testing one should be able to enlist all members of class along with the relationship with superclass so as to ensure that all code branches are covered.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
1) Java reflection provides access to private variables and methods, this exposes the implementation of the class. Such use of class functionalities which break the abstraction can result is portability problems in future upgrades.&lt;br /&gt;
&lt;br /&gt;
2) Reflection involves method execution which resolve at runtime, so with certain Java virtual machines which do not perform optimizations can result in performance overhead with use to Java reflection.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
Ruby is a dynamic language and one of many advantages which Ruby provides is its ability to introspect into a class or object known as reflection. What kind of introspection Ruby provides? It provides a way to inspect class objects using instance_of?, class hierarchy using ancestors, contents &amp;amp; behavior of class like which operations it supports, instance variables, etc and information on methods.&lt;br /&gt;
&lt;br /&gt;
===Dynamic binding : Making reflection possible===&lt;br /&gt;
&lt;br /&gt;
Ruby implements  [http://en.wikipedia.org/wiki/Dynamic_dispatch dynamic binding] of objects. Dynamic binding plays a very important role in [http://en.wikipedia.org/wiki/Metaprogramming meta-programming].&lt;br /&gt;
&lt;br /&gt;
In languages like C,C++; a simple assignment &amp;quot;a = b&amp;quot;, would require 'a' and 'b' to be of the same type. The assignment is interpreted as copying b into a and is implemented by copying the contents of b into the space occupied by a. Thus if 'a' had been declared as an object whose memory size is less than b's object, then object slicing takes place i.e. only that part of 'b' which fits into a's memory would be copied. This behavior might lead to unintended consequences.&lt;br /&gt;
&lt;br /&gt;
[[File:Slicing.gif]]&lt;br /&gt;
&lt;br /&gt;
But dynamic binding in Ruby ensures that the type of object stored in a variable is determined at run time and not at compile time. Thus the assignment &amp;quot;a = b&amp;quot; is interpreted as binding 'a' to the same object that 'b' is bound to. It is implemented by copying the reference stored in b into the (pointer-sized) memory cell of 'a'. Thus 'a' and 'b' point to the same object after the assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Before_binding.png]]        [[File:After_binding.png]]&lt;br /&gt;
&lt;br /&gt;
===Symbols and their usage in reflection techniques===&lt;br /&gt;
&lt;br /&gt;
====Basics====&lt;br /&gt;
[http://en.wikipedia.org/wiki/Symbol_%28programming%29 Symbols] are objects used to represent names and strings inside a Ruby [http://en.wikipedia.org/wiki/Interpreter_%28computing%29 interpreter]. They are immutable and remain unique i.e. every instance of a particular symbol is the same symbol.&lt;br /&gt;
&lt;br /&gt;
====Usage in reflection techniques====&lt;br /&gt;
Symbols are widely used in reflection to invoke methods dynamically. Reflection methods like 'respond_to', 'send' make use of symbols as a reference to other methods. Strings can also be used in place of symbols. However symbols are more efficient compared to strings in terms of memory and performance.&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
====Passing method by reference using a symbol====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Float&lt;br /&gt;
  def poly&lt;br /&gt;
    self*self*self + 2*self*self + 3*self + 4&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And we can pass poly to an integration routine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
area = integrate(:poly, 0, 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Symbols in reflection====&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-send Send] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
irb(main):015:0&amp;gt; to = [:to_s , :to_f]&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
irb(main):016:0&amp;gt; to.each{|method| puts &amp;quot;#{method} =&amp;gt; #{5.send method}&amp;quot;}&lt;br /&gt;
to_s =&amp;gt; 5&lt;br /&gt;
to_f =&amp;gt; 5.0&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-respond_to-3F respond_to] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
5.respond_to? :slice #=&amp;gt; false&lt;br /&gt;
5.respond_to? :to_f #=&amp;gt; true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj = Object.new&lt;br /&gt;
if obj.respond_to?(:program)&lt;br /&gt;
  obj.program&lt;br /&gt;
else&lt;br /&gt;
  puts &amp;quot;Sorry, the object doesn't understand the 'program' message.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===method_missing===&lt;br /&gt;
&lt;br /&gt;
Whenever a call to a method is made on an object , Ruby does a method look up. If the method is not found, Ruby calls a method named '[http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.method_missing method_missing]'. Ruby knows the existence of the 'method_missing' as all objects are instances of 'BasicObject' which includes 'method_missing'. The default behavior of BasicObject#method_missing is to respond by raising a [http://www.ruby-doc.org/core-1.9.2/NoMethodError.html NoMethodError].&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Method_overriding Overriding] 'method_missing' allows users to call methods that don't really exist. The example below illustrates overriding of 'method_missing' to the programmer's advantage. Ruby passes as parameters the name of the method called and the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
'''Example1'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Cat&lt;br /&gt;
  def mew&lt;br /&gt;
    puts &amp;quot;Meow&amp;quot;&lt;br /&gt;
  end  &lt;br /&gt;
  def method_missing(meth, *args)&lt;br /&gt;
    puts &amp;quot;Sorry, I do not #{meth}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
c = Cat.new&lt;br /&gt;
c.mew&lt;br /&gt;
&amp;gt;&amp;gt;Meow&lt;br /&gt;
c.bark&lt;br /&gt;
&amp;gt;&amp;gt; Sorry, I do not bark &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, as the method 'bark' does not exist, method_missing is called with the meth (method name as a symbol) :bark. Hence the result &amp;quot; Sorry, I do not bark &amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''Example2'''&lt;br /&gt;
Using method_missing to convert Roman numerals &amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt; to integers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Roman &lt;br /&gt;
&lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    roman_string.to_s.upcase.split(//).reverse.inject(0) do |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
        last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
      memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end   &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Evaluating Roman.xix calls the xix method of module Roman. Roman has no xix method, so 	method_missing is invoked with :xix as the argument.The id2name method of class Symbol is invoked on xix returning &amp;quot;xix&amp;quot;. The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
''' Example 3 '''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Performer&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    &amp;quot;The duck will #{name}: #{args[0]}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duck = Performer.new&lt;br /&gt;
duck.sing(&amp;quot;Quacking in the Rain&amp;quot;) # =&amp;gt; &amp;quot;The duck will sing: Quacking in the Rain&amp;quot;&lt;br /&gt;
duck.dance(&amp;quot;Swan Lake&amp;quot;) # =&amp;gt; &amp;quot;The duck will dance: Swan Lake&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Applications of Reflection==&lt;br /&gt;
*Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class. &lt;br /&gt;
&lt;br /&gt;
*Programmers who deal with a multitude of classes at the same time can use reflection to create a “serializer” that for a given class uses reflection to go through all the instance variables and processes them accordingly.&lt;br /&gt;
&lt;br /&gt;
*Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.&lt;br /&gt;
&lt;br /&gt;
*Reflection provides the ability to morph the code based on dynamic situations. This provides a sense of artificial intelligence to the program as whole.&lt;br /&gt;
&lt;br /&gt;
*Reflection can be used to debug and verify code as it provides access to the insides of a program.&lt;br /&gt;
&lt;br /&gt;
*Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absense of methods and classes when they are deprecated.&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
Ruby provides a very good reflection ability where one can introspect various properties about an object and the class it belongs to, during runtime. One can obtain the list of methods that are supported on an object by using the 'methods' reflection method on the object. In addition, the 'class' reflection method enables one to query the class that an object belongs to. Similarly, the 'superclass' method allows one to inspect all the super classes of the class that an object belongs to.&lt;br /&gt;
&lt;br /&gt;
In PHP, we have a class called as ReflectionClass which holds the class type for a particlar class. In the class row for PHP we can see that all Reflection operations can be performed on only class Reflection. So as to check if a particular instance belongs to class 'Foo', we need to first create the ReflectionClass object as shown and then call isInstance(argument) method on it. PHP also has getMethods() method which returns a list of class methods.&lt;br /&gt;
&lt;br /&gt;
In Objective C, every type we see is of type class, whether it be String, Integer or Double. So type check in Objective C can be done using method isKindOfClass. But to perform other Reflection tasks, one needs to obtain the object of class first using the object_getClass(Class_Object) method. Once this object is obtained we can then perform operations like getting method list, etc as shown in table. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Ruby&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | PHP&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Objective C&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Class&lt;br /&gt;
|Method: instance_of?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.instance_of? String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isInstance()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$class = new ReflectionClass('Foo');&lt;br /&gt;
if ($class-&amp;gt;isInstance($arg)) {&lt;br /&gt;
   echo &amp;quot;Yes&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myObject isKindOfClass:[MyObject class])&lt;br /&gt;
{&lt;br /&gt;
//do something&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Method&lt;br /&gt;
|Method: methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 list = r.methods &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::getMethods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $class = new ReflectionClass('Apple');&lt;br /&gt;
$methods = $class-&amp;gt;getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: class_copyMethodList() &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SomeClass * t = [[SomeClass alloc] init];&lt;br /&gt;
unsigned int mc = 0;&lt;br /&gt;
Method * mlist = &lt;br /&gt;
class_copyMethodList&lt;br /&gt;
(object_getClass(t), &amp;amp;mc);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Type&lt;br /&gt;
|Method: Object.class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;quot;Hello&amp;quot;.class&lt;br /&gt;
&amp;gt;&amp;gt;String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: gettype()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$data = array(1, 'foo');&lt;br /&gt;
foreach ($data as $value) {&lt;br /&gt;
    echo gettype($value), &amp;quot;\n&amp;quot;;&lt;br /&gt;
}?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myDemo isKindOfClass:[DemoClass class]])&lt;br /&gt;
{&lt;br /&gt;
    //code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | String representation of an object&lt;br /&gt;
|Method: to_s &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.to_s &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::__toString —&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$reflectionClass = &lt;br /&gt;
new ReflectionClass(MyDemoClass);&lt;br /&gt;
echo $reflectionClass-&amp;gt;__toString();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: [NSString stringWithFormat:&amp;quot;&amp;quot;]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*objString = [NSString &lt;br /&gt;
stringWithFormat:”%@”,myObject]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages and Disadvantages of reflection==&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility:&amp;lt;/b&amp;gt; Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.&lt;br /&gt;
* &amp;lt;b&amp;gt;Class browsers in IDEs:&amp;lt;/b&amp;gt; The ability to examine the members of classes makes implementation of visual aids, auto-completion and documentation easy in development tools for programmers.&lt;br /&gt;
* &amp;lt;b&amp;gt;Debugging and Test Harness:&amp;lt;/b&amp;gt; Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions. Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.&lt;br /&gt;
* &amp;lt;b&amp;gt;Correctness:&amp;lt;/b&amp;gt; Reflection improves the robustness and the correctness of a program  especially in dynamically typed languages as runtime checks can be added to check the availability of the methods or classes.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Performance Overhead:&amp;lt;/b&amp;gt; Reflection resolves types of objects and classes are dynamically at runtime, this introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.&lt;br /&gt;
* &amp;lt;b&amp;gt;Security: &amp;lt;/b&amp;gt; At run-time binding in reflection we loose the security of compile time checks and verification. It also provides access to the internals of a class or an encapsulated object like private methods and variables which makes security a major issue.&lt;br /&gt;
*&amp;lt;b&amp;gt;Portability: &amp;lt;/b&amp;gt; Another issue is of portability, over a period of time the code may change during updates and a Reflective code breaks abstraction. Such a code may change behavior during updates and may become dysfunctional. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Reading==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]&lt;br /&gt;
*[http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
*[http://tutorials.jenkov.com/java-reflection/classes.html Java Reflection]&lt;br /&gt;
*[http://www.slideshare.net/CiaranMcHale/java-reflection-explained-simply Java reflection basics]&lt;br /&gt;
*[http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation]&lt;br /&gt;
*[http://www.quora.com/Computer-Programming/How-is-reflection-useful Uses of reflection]&lt;br /&gt;
*[http://download.oracle.com/javase/tutorial/reflect/index.html Java reflection official website]&lt;br /&gt;
*[http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Ruby Documentation]&lt;br /&gt;
*[http://www.slideshare.net/MarcusDenker/behavioral-reflection Behavioral reflection]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66535</id>
		<title>CSC/ECE 517 Fall 2012/ch1b 1w40 as</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1b_1w40_as&amp;diff=66535"/>
		<updated>2012-10-03T21:58:23Z</updated>

		<summary type="html">&lt;p&gt;Svmankar: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29 Reflection ]is a relatively common [http://en.wikipedia.org/wiki/Computer_programming computer programming] concept where in the program has the inherent ability to examine itself at run time. Based on its observations the program can modify it's behavior for the given situation.The modifications can be any aspect of the programming language .i.e syntax, semantics, or implementation. Precisely, &amp;quot;Reflection&amp;quot; can be defined as a language's ability to inspect and dynamically call [http://en.wikipedia.org/wiki/Class_%28computer_programming%29 classes], methods, attributes, etc. at runtime. More advanced uses of reflection let you list and call methods, [http://en.wikipedia.org/wiki/Constructor_%28object-oriented_programming%29 constructors], etc.&lt;br /&gt;
&lt;br /&gt;
Reflection is important since it lets you write programs that does not have to &amp;quot;know&amp;quot; everything at compile time, making them more dynamic, since they can be tied together at runtime. For example in a high level object oriented language the ability to inspect its class , interfaces and methods at run time without knowing their names at compile time. It provides the ability to modify , instantiate and access to methods such as getter's and setter's of a class. Since the program need not have all the information at compile time it makes the program more dynamic. The code can be written against known interfaces, but the actual classes to be used can be instantiated using reflection from configuration files. Lots of modern frameworks uses reflection extensively for this very reason. In [http://en.wikipedia.org/wiki/Scripting_language scripting languages] like Python reflection is even more tightly integrated, since it matches more naturally with the general programming model.&lt;br /&gt;
&lt;br /&gt;
Reflection as a concept was first introduced in the doctoral dissertation of Dr. Brian Cantwell Smith&amp;lt;ref&amp;gt;[http://hdl.handle.net/1721.1/15961 Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD Thesis, 1982.]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://publications.csail.mit.edu/lcs/specpub.php?id=840 Brian C. Smith. Reflection and semantics in a procedural language. Technical Report MIT-LCS-TR-272, Massachusetts Institute of Technology, Cambridge, Mass., January 1982.]&amp;lt;/ref&amp;gt; in 1992.&lt;br /&gt;
&lt;br /&gt;
In the simple illustration provided below in ruby we can see how the name of a class can be obtained from the object and how we can get the ancestor classes and modules of a particular class. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
7.class #=&amp;gt; Fixnum&lt;br /&gt;
&lt;br /&gt;
&amp;quot;helloworld&amp;quot;.class #=&amp;gt; String&lt;br /&gt;
&lt;br /&gt;
String.ancestors #=&amp;gt; [String, Enumerable, Comparable, Object, Kernel]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Some of the common information that can be obtained from reflection are :&lt;br /&gt;
* Object type&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Superclass_%28computer_science%29#Subclasses_and_superclasses Super classes] of any class&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Method_(computer_programming) Methods]&lt;br /&gt;
* class fields&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/concepts/interface.html Interfaces]&lt;br /&gt;
&lt;br /&gt;
These are discussed in detail in the below sections.&lt;br /&gt;
Common languages that exhibit reflection to varying degrees are Ruby, Java, Smalltalk, C# and more.&lt;br /&gt;
&lt;br /&gt;
There are two basic types of reflection:&lt;br /&gt;
* Behavioral Reflection: This type of reflection changes the behaviour of the execution of the program based on observation and modification.&lt;br /&gt;
* Structural Reflection: This type of reflection deals with changing the very structure of the program such as the data structures and flow of control in the program.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
There are many challenges faced by designers of reflective languages. They must provide as much leeway as possible for late binging and at the same time they must optimize the compilation of the static components so that they are ready for run-time. Reflection is in essense a connection between the object-level (program) and meta-level (the processor). The ability of the object level to be able to observe and modify the meta-level information is the consequence of this connection. These actions can be termed as [http://en.wikipedia.org/wiki/Type_introspection introspection] (This involves the action of observing the class) and intercession (this involves the operation of modifying the behavior of the class). These actions can  implemented with the implementation of the following components:&lt;br /&gt;
&lt;br /&gt;
* Ability to create [http://en.wikipedia.org/wiki/First-class_object first class objects] ie  [http://en.wikipedia.org/wiki/Reification_(computer_science) reification]. &lt;br /&gt;
&lt;br /&gt;
* Ability to convert a string that denotes a class or a method into its corresponding    reference or invocation.&lt;br /&gt;
&lt;br /&gt;
* Ability to use and create symbolic links to methods and classes.&lt;br /&gt;
&lt;br /&gt;
==Reflection in C# ==&lt;br /&gt;
===Features===&lt;br /&gt;
In C#, Reflection uses the type system. C# is a [http://en.wikipedia.org/wiki/Strong_typing strongly-typed] language in which every variable and constant has a type. Not only this, but every expression that evaluates to a value is also associated with a type. Every method signature specifies a type for each input parameter and for the return value. A typical C# program uses the types from the class library as an addition to the user-defined types that are specific to the program's problem domain.&lt;br /&gt;
&lt;br /&gt;
C# maintains a special database called the [http://en.wikipedia.org/wiki/Metadata ‘metadata’] where a compiled C# program is usually encoded and stored. This metadata can then be used by reflection to act upon and read the required data present in it. This provides astonishing features such as accessing the members of an object or class based on their string names. This can be done by using the System.Reflection namespace provided in C#.&lt;br /&gt;
&lt;br /&gt;
As an example, the below program uses the System.Reflection namespace to access the metadata of itself. It searches for the public field with the name &amp;quot;_mynumber&amp;quot; and then acquires its value.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _mynumber = 4;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    Type type = typeof(ReflectionUsage);&lt;br /&gt;
    FieldInfo info = type.GetField(&amp;quot;_mynumber&amp;quot;);&lt;br /&gt;
    object obj = type.GetValue(null);&lt;br /&gt;
    Console.WriteLine(obj);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This program would then output the number ‘4’ which is the value that is assigned to the variable “_mynumber”.&lt;br /&gt;
&lt;br /&gt;
Here is how the System.Reflection class contains in C#.&lt;br /&gt;
&lt;br /&gt;
[[File:Csharp.jpg]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Below are the several powerful reflection features that are provided by C#:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Field Reflection:&amp;lt;/b&amp;gt; This gives the power to scan or search the fields in your C# program by using the GetField or GetFields methods. Using this reflection we can load field values and then loop through those fields and display their names and values. The System.Reflection namespace provides a powerful and maintainable way to enumerate fields and properties. It can then access these fields by name.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;SetValue Reflection:&amp;lt;/b&amp;gt; SetValue accesses the fields by their names. We can take a string that usually represents a target field, and then using the System.Reflection namespace methods, change the actual value of that field.&lt;br /&gt;
Below is an example that does precisely this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectionUsage&lt;br /&gt;
{&lt;br /&gt;
   public static int _myfield;&lt;br /&gt;
   static void Main()&lt;br /&gt;
   {&lt;br /&gt;
    FieldInfo info = typeof(ReflectionUsage).GetField(&amp;quot;_myfield&amp;quot;);&lt;br /&gt;
    info.SetValue(null, 2012);&lt;br /&gt;
    Console.WriteLine(_myfield);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above program would output 2012 which is the value that we set using the SetValue reflection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;MethodInfo Invoke:&amp;lt;/b&amp;gt; Let us say we have the name of a method in the string format and want to invoke it. In such a case, one can use the GetMethod method and then invoke the MethodInfo that can be acquired from it. The invoke method can be called to invoke method with the name specified by the string.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Type Reflection:&amp;lt;/b&amp;gt; Type is one of the most important types when using reflection in C#. The Type type is used to describe data types. It stores the C# type information in a variable, property or field and can be used as an argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Sizeof:&amp;lt;/b&amp;gt; The sizeof operator exposes information about the implementation of types in the code. It does not require the System.Reflection namespace. However, it is related to reflection in the sense that it expresses information about the program itself.&lt;br /&gt;
&lt;br /&gt;
===Advantages:===&lt;br /&gt;
&lt;br /&gt;
1. In C#, one can write code that uses for example a System.Xml.XMLDataDocument class, which loads and parses an XML document and then allows you to parse the DOM during runtime. During parsing, every time that an &amp;lt;object&amp;gt; node is scanned, a new object needs to be created using its FQN (fully qualified name). Every time a &amp;lt;property&amp;gt; node is parsed, then its parent node's property needs to be set to a newly created object. Also, every time that a &amp;lt;function&amp;gt; node is parsed, the parent object that is created must have the function, by name, called on it using the arguments that are later defined. This would allow you to create any object type that you want, and set properties and call functions for initialization, in a very recursive manner. The use of reflection would render this code to be surprisingly small because it takes advantage of recursion and the generic nature of reflection.&lt;br /&gt;
&lt;br /&gt;
2. Programs that use reflection have the ability to look inside themselves to see their own inner workings and structure. This capacity can lend them unique and powerful features that can be used to write better code.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages:===&lt;br /&gt;
&lt;br /&gt;
1. One main disadvantage of using reflection would be that reflection in general is that they can render programs that are less clear to read, harder to understand. A new person reading the code can find it hard to grasp what the code is actually doing.&lt;br /&gt;
&lt;br /&gt;
2. Another disadvantage is that it can render programs that are generally slower.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Java==&lt;br /&gt;
Reflection is a part of Java API which enables Java code to inspect and reflect Java components like class and objects during runtime. Classes in the java.lang.reflect package along with java.lang.Class and java.lang.Package take care of applications like degugger, interpreters, objects inspectors, class browsers. Important protocols such as SOAP and JavaBeans would not have been possible, if it weren't for Reflection. The aid a developer gets from an IDE during coding is achieved by using nothing else but Reflection. Reflection is one of the advanced features of Java, it gives runtime information about the objects, classes, fields and methods in a class, interfaces, etc. The image below shows some major functions related to java reflection. &lt;br /&gt;
&lt;br /&gt;
[[File:Tjava_reflection.gif]]&lt;br /&gt;
&lt;br /&gt;
Now we will have a look at some of the important features in Java Reflection and will see how they are implemented.&lt;br /&gt;
===Features ===&lt;br /&gt;
&amp;lt;b&amp;gt;Classes: &amp;lt;/b&amp;gt;&lt;br /&gt;
The first thing any programmer would do using reflection would be to inspect Java classes at runtime. The java package java.lang.Class helps to gather all important information about the class at runtime. We can obtain class name, class modifiers, constructors, field, method, superclass, implemented interface etc. &lt;br /&gt;
&lt;br /&gt;
Before you can do any inspection on a class you need to obtain its java.lang.Class object. All types in Java including the primitive types (int, long, float etc.) including arrays have an associated Class object. If you know the name of the class at compile time you can obtain a Class object like this:&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
String className = obtainClass.getName();&lt;br /&gt;
 System.out.printf(&amp;quot;ClassName: %s\n&amp;quot;,className);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Constructors: &amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Java reflection one can inspect the constructors of classes and instantiate object of that class at runtime. This is done using Java class java.lang.reflect.Constructor. The steps to do this operation are as follows:&lt;br /&gt;
1) obtaining constructor objects&lt;br /&gt;
2) get constructor parameters&lt;br /&gt;
3) Instantiating Objects using constructors&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
import java.lang.reflect.*;&lt;br /&gt;
public class DemoClass{&lt;br /&gt;
&lt;br /&gt;
public String msg;&lt;br /&gt;
&lt;br /&gt;
public DemoClass(String forMsg){&lt;br /&gt;
msg = forMsg;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static void main(String[] args)&lt;br /&gt;
{&lt;br /&gt;
try{&lt;br /&gt;
Class obtainClass = DemoClass.class;&lt;br /&gt;
Constructor constructor = obtainClass.getConstructor(new Class[]{String.class});&lt;br /&gt;
DemoClass myDemo = (DemoClass)constructor.newInstance(&amp;quot;Welcome to Java Reflection&amp;quot;);&lt;br /&gt;
System.out.printf(&amp;quot;New Instance String: %s\n&amp;quot;,myDemo.msg);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
catch(Exception e)&lt;br /&gt;
{&lt;br /&gt;
System.err.printf(e.getMessage());&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt; Field: &amp;lt;/b&amp;gt;&lt;br /&gt;
	Inspecting the fields of classes and get/set them at runtime is another feature provided by Java Reflection. This is done using Java class java.lang.reflect.Field. To get/set a field value using Java reflection following are steps involved: obtaining field objects, field name, field type and getting and setting field values.&lt;br /&gt;
eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getFields();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt; Methods: &amp;lt;/b&amp;gt;&lt;br /&gt;
One can also inspect the methods of class at runtime and invoke them. The class to implement this functionality is  java.lang.reflect.Method. The steps to obtain methods from a class are:&lt;br /&gt;
Obtaining Method Objects&lt;br /&gt;
Method Parameters and Return Types&lt;br /&gt;
Invoking Methods using Method object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class objClass = MyObject.class;&lt;br /&gt;
Field[] methods = objClass.getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
&lt;br /&gt;
1) One of the major advantage of Java reflection is in debugging. While debugging one should be able to examine the private members of classes. &lt;br /&gt;
2) Also while testing one should be able to enlist all members of class along with the relationship with superclass so as to ensure that all code branches are covered.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
1) Java reflection provides access to private variables and methods, this exposes the implementation of the class. Such use of class functionalities which break the abstraction can result is portability problems in future upgrades.&lt;br /&gt;
&lt;br /&gt;
2) Reflection involves method execution which resolve at runtime, so with certain Java virtual machines which do not perform optimizations can result in performance overhead with use to Java reflection.&lt;br /&gt;
&lt;br /&gt;
==Reflection in Ruby==&lt;br /&gt;
Ruby is a dynamic language and one of many advantages which Ruby provides is its ability to introspect into a class or object known as reflection. What kind of introspection Ruby provides? It provides a way to inspect class objects using instance_of?, class hierarchy using ancestors, contents &amp;amp; behavior of class like which operations it supports, instance variables, etc and information on methods.&lt;br /&gt;
&lt;br /&gt;
===Dynamic binding : Making reflection possible===&lt;br /&gt;
&lt;br /&gt;
Ruby implements  [http://en.wikipedia.org/wiki/Dynamic_dispatch dynamic binding] of objects. Dynamic binding plays a very important role in [http://en.wikipedia.org/wiki/Metaprogramming meta-programming].&lt;br /&gt;
&lt;br /&gt;
In languages like C,C++; a simple assignment &amp;quot;a = b&amp;quot;, would require 'a' and 'b' to be of the same type. The assignment is interpreted as copying b into a and is implemented by copying the contents of b into the space occupied by a. Thus if 'a' had been declared as an object whose memory size is less than b's object, then object slicing takes place i.e. only that part of 'b' which fits into a's memory would be copied. This behavior might lead to unintended consequences.&lt;br /&gt;
&lt;br /&gt;
[[File:Slicing.gif]]&lt;br /&gt;
&lt;br /&gt;
But dynamic binding in Ruby ensures that the type of object stored in a variable is determined at run time and not at compile time. Thus the assignment &amp;quot;a = b&amp;quot; is interpreted as binding 'a' to the same object that 'b' is bound to. It is implemented by copying the reference stored in b into the (pointer-sized) memory cell of 'a'. Thus 'a' and 'b' point to the same object after the assignment.&lt;br /&gt;
&lt;br /&gt;
[[File:Before_binding.png]]        [[File:After_binding.png]]&lt;br /&gt;
&lt;br /&gt;
===Symbols and their usage in reflection techniques===&lt;br /&gt;
&lt;br /&gt;
====Basics====&lt;br /&gt;
[http://en.wikipedia.org/wiki/Symbol_%28programming%29 Symbols] are objects used to represent names and strings inside a Ruby [http://en.wikipedia.org/wiki/Interpreter_%28computing%29 interpreter]. They are immutable and remain unique i.e. every instance of a particular symbol is the same symbol.&lt;br /&gt;
&lt;br /&gt;
====Usage in reflection techniques====&lt;br /&gt;
Symbols are widely used in reflection to invoke methods dynamically. Reflection methods like 'respond_to', 'send' make use of symbols as a reference to other methods. Strings can also be used in place of symbols. However symbols are more efficient compared to strings in terms of memory and performance.&lt;br /&gt;
&lt;br /&gt;
====Examples====&lt;br /&gt;
&lt;br /&gt;
====Passing method by reference using a symbol====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Float&lt;br /&gt;
  def poly&lt;br /&gt;
    self*self*self + 2*self*self + 3*self + 4&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
And we can pass poly to an integration routine:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
area = integrate(:poly, 0, 10)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Symbols in reflection====&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-send Send] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
irb(main):015:0&amp;gt; to = [:to_s , :to_f]&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
irb(main):016:0&amp;gt; to.each{|method| puts &amp;quot;#{method} =&amp;gt; #{5.send method}&amp;quot;}&lt;br /&gt;
to_s =&amp;gt; 5&lt;br /&gt;
to_f =&amp;gt; 5.0&lt;br /&gt;
=&amp;gt; [:to_s, :to_f]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/core-1.9.2/Object.html#method-i-respond_to-3F respond_to] method&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
5.respond_to? :slice #=&amp;gt; false&lt;br /&gt;
5.respond_to? :to_f #=&amp;gt; true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj = Object.new&lt;br /&gt;
if obj.respond_to?(:program)&lt;br /&gt;
  obj.program&lt;br /&gt;
else&lt;br /&gt;
  puts &amp;quot;Sorry, the object doesn't understand the 'program' message.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===method_missing===&lt;br /&gt;
&lt;br /&gt;
Whenever a call to a method is made on an object , Ruby does a method look up. If the method is not found, Ruby calls a method named '[http://ruby-doc.org/docs/ProgrammingRuby/html/ref_c_object.html#Object.method_missing method_missing]'. Ruby knows the existence of the 'method_missing' as all objects are instances of 'BasicObject' which includes 'method_missing'. The default behavior of BasicObject#method_missing is to respond by raising a [http://www.ruby-doc.org/core-1.9.2/NoMethodError.html NoMethodError].&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Method_overriding Overriding] 'method_missing' allows users to call methods that don't really exist. The example below illustrates overriding of 'method_missing' to the programmer's advantage. Ruby passes as parameters the name of the method called and the arguments passed to it.&lt;br /&gt;
&lt;br /&gt;
'''Example1'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Cat&lt;br /&gt;
  def mew&lt;br /&gt;
    puts &amp;quot;Meow&amp;quot;&lt;br /&gt;
  end  &lt;br /&gt;
  def method_missing(meth, *args)&lt;br /&gt;
    puts &amp;quot;Sorry, I do not #{meth}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
c = Cat.new&lt;br /&gt;
c.mew&lt;br /&gt;
&amp;gt;&amp;gt;Meow&lt;br /&gt;
c.bark&lt;br /&gt;
&amp;gt;&amp;gt; Sorry, I do not bark &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, as the method 'bark' does not exist, method_missing is called with the meth (method name as a symbol) :bark. Hence the result &amp;quot; Sorry, I do not bark &amp;quot;&lt;br /&gt;
&lt;br /&gt;
'''Example2'''&lt;br /&gt;
Using method_missing to convert Roman numerals &amp;lt;ref&amp;gt;http://www.rubyquiz.com/quiz22.html&amp;lt;/ref&amp;gt; to integers&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Roman &lt;br /&gt;
&lt;br /&gt;
  DIGITS = {&lt;br /&gt;
    'I' =&amp;gt; 1,&lt;br /&gt;
    'V' =&amp;gt; 5,&lt;br /&gt;
    'X' =&amp;gt; 10,&lt;br /&gt;
    'L' =&amp;gt; 50,&lt;br /&gt;
    'C' =&amp;gt; 100,&lt;br /&gt;
    'D' =&amp;gt; 500,&lt;br /&gt;
    'M' =&amp;gt; 1000,&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def roman_to_integer(roman_string)&lt;br /&gt;
    last = nil&lt;br /&gt;
    roman_string.to_s.upcase.split(//).reverse.inject(0) do |memo, digit|&lt;br /&gt;
      if digit_value = DIGITS[digit]&lt;br /&gt;
        if last &amp;amp;&amp;amp; last &amp;gt; digit_value&lt;br /&gt;
          memo -= digit_value&lt;br /&gt;
        else&lt;br /&gt;
          memo += digit_value&lt;br /&gt;
        end&lt;br /&gt;
        last = digit_value&lt;br /&gt;
      end&lt;br /&gt;
      memo&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(method)        &lt;br /&gt;
    str = method.id2name &lt;br /&gt;
    roman_to_integer(str)      &lt;br /&gt;
  end   &lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Evaluating Roman.xix calls the xix method of module Roman. Roman has no xix method, so 	method_missing is invoked with :xix as the argument.The id2name method of class Symbol is invoked on xix returning &amp;quot;xix&amp;quot;. The &amp;quot;xix&amp;quot; is then parsed according to the rules for evaluating Roman numerals, and evaluates to 19.&lt;br /&gt;
&lt;br /&gt;
''' Example 3 '''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Performer&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    &amp;quot;The duck will #{name}: #{args[0]}&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
duck = Performer.new&lt;br /&gt;
duck.sing(&amp;quot;Quacking in the Rain&amp;quot;) # =&amp;gt; &amp;quot;The duck will sing: Quacking in the Rain&amp;quot;&lt;br /&gt;
duck.dance(&amp;quot;Swan Lake&amp;quot;) # =&amp;gt; &amp;quot;The duck will dance: Swan Lake&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Applications of Reflection==&lt;br /&gt;
*Reflection has become invaluable to programmers who need to connect code with data. For example in a GUI environment a button might need to invoke different methods in different classes. Reflection can be used here to call the method on any given class. &lt;br /&gt;
&lt;br /&gt;
*Programmers who deal with a multitude of classes at the same time can use reflection to create a “serializer” that for a given class uses reflection to go through all the instance variables and processes them accordingly.&lt;br /&gt;
&lt;br /&gt;
*Reflection is used in large test frameworks where reflection helps in identifying the test methods for different scenarios.&lt;br /&gt;
&lt;br /&gt;
*Reflection provides the ability to morph the code based on dynamic situations. This provides a sense of artificial intelligence to the program as whole.&lt;br /&gt;
&lt;br /&gt;
*Reflection can be used to debug and verify code as it provides access to the insides of a program.&lt;br /&gt;
&lt;br /&gt;
*Reflection is very useful when the software is upgraded regularly. It provides an easy method to check for available methods and classes. This prevents the errors caused by the absense of methods and classes when they are deprecated.&lt;br /&gt;
&lt;br /&gt;
==Feature Comparison==&lt;br /&gt;
Ruby provides a very good reflection ability where one can introspect various properties about an object and the class it belongs to, during runtime. One can obtain the list of methods that are supported on an object by using the 'methods' reflection method on the object. In addition, the 'class' reflection method enables one to query the class that an object belongs to. Similarly, the 'superclass' method allows one to inspect all the super classes of the class that an object belongs to.&lt;br /&gt;
&lt;br /&gt;
In PHP, we have a class called as ReflectionClass which holds the class type for a particlar class. In the class row for PHP we can see that all Reflection operations can be performed on only class Reflection. So as to check if a particular instance belongs to class 'Foo', we need to first create the ReflectionClass object as shown and then call isInstance(argument) method on it. PHP also has getMethods() method which returns a list of class methods.&lt;br /&gt;
&lt;br /&gt;
In Objective C, every type we see is of type class, whether it be String, Integer or Double. So type check in Objective C can be done using method isKindOfClass. But to perform other Reflection tasks, one needs to obtain the object of class first using the object_getClass(Class_Object) method. Once this object is obtained we can then perform operations like getting method list, etc as shown in table. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Ruby&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | PHP&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Objective C&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Class&lt;br /&gt;
|Method: instance_of?&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.instance_of? String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isInstance()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$class = new ReflectionClass('Foo');&lt;br /&gt;
if ($class-&amp;gt;isInstance($arg)) {&lt;br /&gt;
   echo &amp;quot;Yes&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myObject isKindOfClass:[MyObject class])&lt;br /&gt;
{&lt;br /&gt;
//do something&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Method&lt;br /&gt;
|Method: methods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 list = r.methods &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::getMethods&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 $class = new ReflectionClass('Apple');&lt;br /&gt;
$methods = $class-&amp;gt;getMethods();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: class_copyMethodList() &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SomeClass * t = [[SomeClass alloc] init];&lt;br /&gt;
unsigned int mc = 0;&lt;br /&gt;
Method * mlist = &lt;br /&gt;
class_copyMethodList&lt;br /&gt;
(object_getClass(t), &amp;amp;mc);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | Type&lt;br /&gt;
|Method: Object.class&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;quot;Hello&amp;quot;.class&lt;br /&gt;
&amp;gt;&amp;gt;String&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: gettype()&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$data = array(1, 'foo');&lt;br /&gt;
foreach ($data as $value) {&lt;br /&gt;
    echo gettype($value), &amp;quot;\n&amp;quot;;&lt;br /&gt;
}?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: isKindOfClass&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if([myDemo isKindOfClass:[DemoClass class]])&lt;br /&gt;
{&lt;br /&gt;
    //code&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; style=&amp;quot;background:#efefef;&amp;quot; | String representation of an object&lt;br /&gt;
|Method: to_s &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
obj.to_s &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: ReflectionClass::__toString —&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$reflectionClass = &lt;br /&gt;
new ReflectionClass(MyDemoClass);&lt;br /&gt;
echo $reflectionClass-&amp;gt;__toString();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|Method: [NSString stringWithFormat:&amp;quot;&amp;quot;]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*objString = [NSString &lt;br /&gt;
stringWithFormat:”%@”,myObject]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Advantages and Disadvantages of reflection==&lt;br /&gt;
&lt;br /&gt;
===Advantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Extensibility:&amp;lt;/b&amp;gt; Reflection provides the capability of using external and user defined classes by instantiation of extensibility objects using their fully qualified names.&lt;br /&gt;
* &amp;lt;b&amp;gt;Class browsers in IDEs:&amp;lt;/b&amp;gt; The ability to examine the members of classes makes implementation of visual aids, auto-completion and documentation easy in development tools for programmers.&lt;br /&gt;
* &amp;lt;b&amp;gt;Debugging and Test Harness:&amp;lt;/b&amp;gt; Reflection allows the user to observe the private members in classes. This capability can be used to debug classes and their interactions. Reflection can be used to call a set of testing APIs defined on a class for maximum coverage of testing.&lt;br /&gt;
* &amp;lt;b&amp;gt;Correctness:&amp;lt;/b&amp;gt; Reflection improves the robustness and the correctness of a program  especially in dynamically typed languages as runtime checks can be added to check the availability of the methods or classes.&lt;br /&gt;
&lt;br /&gt;
===Disadvantages===&lt;br /&gt;
* &amp;lt;b&amp;gt;Performance Overhead:&amp;lt;/b&amp;gt; Reflection resolves types of objects and classes are dynamically at runtime, this introduces lot of performance overhead when compared to non-reflective code. Hence it should be used judiciously.&lt;br /&gt;
* &amp;lt;b&amp;gt;Security: &amp;lt;/b&amp;gt; At run-time binding in reflection we loose the security of compile time checks and verification. It also provides access to the internals of a class or an encapsulated object like private methods and variables which makes security a major issue.&lt;br /&gt;
*&amp;lt;b&amp;gt;Portability: &amp;lt;/b&amp;gt; Another issue is of portability, over a period of time the code may change during updates and a Reflective code breaks abstraction. Such a code may change behavior during updates and may become dysfunctional. &lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This article makes an attempt to explain the concept of Reflection in Object Oriented Programming. The article mentions the different approaches to reflection in Ruby and other languages.It mentions the usage of Reflections and the advantages and disadvantages of using Reflection. A follow up to this article would be to study the concept of [http://en.wikipedia.org/wiki/Metaprogramming Metaprogramming].&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Reading==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Reflection_(computer_programming) Reflection]&lt;br /&gt;
*[http://www.cs.indiana.edu/~jsobel/rop.html An Introduction to Reflection-Oriented Programming]&lt;br /&gt;
*[http://tutorials.jenkov.com/java-reflection/classes.html Java Reflection]&lt;br /&gt;
*[http://www.slideshare.net/CiaranMcHale/java-reflection-explained-simply Java reflection basics]&lt;br /&gt;
*[http://www2.parc.com/csl/groups/sda/projects/reflection96/docs/malenfant/ref96/ref96.html A Tutorial on Behavioral Reflection and its Implementation]&lt;br /&gt;
*[http://www.quora.com/Computer-Programming/How-is-reflection-useful Uses of reflection]&lt;br /&gt;
*[http://download.oracle.com/javase/tutorial/reflect/index.html Java reflection official website]&lt;br /&gt;
*[http://ruby-doc.org/docs/ProgrammingRuby/html/builtins.html Ruby Documentation]&lt;br /&gt;
*[http://www.slideshare.net/MarcusDenker/behavioral-reflection Behavioral reflection]&lt;/div&gt;</summary>
		<author><name>Svmankar</name></author>
	</entry>
</feed>