The idea is two fold:
- It is sometimes very difficult to get a real database to act in all the ways you want to test against without having to jump through hoops. For instance, with a mock DB object, testing how your app will perform when the DB connection goes down can be automated by making the mock DB object mimic that. To replicate this in reality and automate it would be difficult at best.
- Mock objects do not test the actions of the objects they are mocking (the DB in this case) but the objects which use it. So in my particular instance I want to test my objects that use the database, but I really dont care about the database, as that is not (in this case) relevant to the test itself.
This site
http://www.mockobjects.com and in particular the
FAQ are great introductions to the idea behind Mock objects.
-stvn