Mockito First Application - Mockito

What is the process of Mockito first application?

Following example describes about mock of Stock Service to get the dummy price of some stocks and unit tested a java class named Portfolio.

Here’s the step-by-step process of the application:

Step 1 − Create a JAVA class to represent the Stock


Step 2 − Create an interface StockService to get the price of a stock


Step 3 − Create a class Portfolio to represent the portfolio of any client


Step 4 − Test the Portfolio class

Now test the Portfolio class, by injecting in it a mock of stockservice. Mock will be created by Mockito.


Step 5 − Verify the result

Compile the classes using javac compiler as follows –
Now run the PortfolioTester to see the result –

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Mockito Topics