Mocking and Stubbing in Java - (JUnit, etc)
Currently our junit tests all eventualy read the database to fill the objects and test code.
My question is, isnt it a better practice to mock/stub and avoid the trip to the database, since we are testing the logic, not the database connection?
But if my thought is right on mocking and stubbing, how can it be made possible?
For example. Lets say I have class foo which calls dataHandler.java which in turn called dataAccessor.java. There is no way that I know of that inside the foo class we could tell the dataHandler class to override the dataAccessor class and instead of using that dataAccessor which calls the database, use another class such as dataAccessorForUnitTesting and inside that class simply fill the requested object with dummy data and return it. Basically saying foo cannot override a class thats multilpe levels deep.
Just looking for some suggestions on people who use testing such as junit. If the right way is to read the database, then so be it. I'd just like someone to point that out from their experience.