Mocking in Java using Mockito

Before talking about Mockito Framework. Let’s see why do we need it at the first place and how it can be helpful. Last year, I was working on one project which talks to other third party services as well as with the database connection and to test the functionality of my application, third party application should be up and running. There can be a chance where all these services might not available during unit testing. As you can see, your application is completely dependent on other application and what if: Third party application is down You cannot connect to database to test your functionality At such situation, mocking becomes a natural solution for unit testing. Using Mockito, you don’t really need a database connection. You just need a mock object that returns the expected result. Mockito: Introduction Mockito is a mocking framework, the JAVA-based library that is used for effective unit tes...