Question: Stub or Mock in JUnit
What is stub and Mock in JUnit? Please give one real time example so that i can understand easily.
Consider a situation, where you have a class Calculator, that needs a dao (Data Access Object) object to load the data it needs from a database. Setting up the connection and inserting the data in the database can be a lot of work.
Instead you can provide the Calculator instance with a fake dao class which just returns the data you need for the test. The fake dao class will not actually read the data from the database. The fake dao class is a mock object or stub object.