The purpose of a unit test is to verify an assumption about the behavior of a software system. And unit tests must be automated so that any assumptions can be verified quickly.
A unit test should also exhibit the following characteristics:
- It should have fast test execution.
- A test should not depend on database access or any long running tasks. A test should isolate external dependencies.
A Mock Object is an object that substitutes for a real object. Mock objects are simulated objects that mimic the behavior of real objects. Mock objects allow you to set up test scenarios without using large resources like databases. Instead of calling a database for testing, you can simulate your database using a mock object in your unit tests. This makes tests run faster.
From the blog Software Testing – The blog about software by Sudarshan and used with permission of the author. All other rights reserved by the author.