top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the functionality of the stub in Java?

+2 votes
280 views
What is the functionality of the stub in Java?
posted Aug 27, 2015 by Karthick.c

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Lets take an example:
In unit testing,There are three types of fake objects you can use for testing: Stubs, Mocks and Proxies.
A Stub is an object that implements an interface of a component, but instead of returning what the component would return when called, the stub can be configured to return a value that suits the test. Using stubs a unit test can test if a unit can handle various return values from its collaborator. Using a stub instead of a real collaborator in a unit test could be expressed like this:
unit test --> stub
unit test --> unit --> stub
unit test asserts on results and state of unit
First the unit test creates the stub and configures its return values. Then the unit test creates the unit and sets the stub on it. Now the unit test calls the unit which in turn calls the stub. Finally the unit test makes assertions about the results of the method calls on the unit.

answer Mar 14, 2016 by Shivam Kumar Pandey
...