JUNIT using Mockito

Here an example unit test code snippet.
Please include the following libraries as provided. if there is some problem with junit-4-11.jar, hamcrest-core.1.3.jar may be needed.

The example shows how we can Mock the return values of the `p` Object, where we do not need to run through all the inner methods of `p`, just create a mock return value.

junit-4.11.jar
mockito-all-1.8.5.jar
( optional ) hamcrest-core.1.3.jar

import org.mockito.Mockito;

....

Property p = Mockito.mock(Property.class);
Mockito.stub(p.getWords()).toReturn("school,rock");
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s