volume_mute

Mock Object Example - Database

publish date2026/06/17 05:25:32.075603 UTC

volume_mute

A development team is unit testing a class that calls a database to retrieve customer records. The database setup takes 30 seconds each test run. They decide to use a mock object. What would the mock object database typically contain?

Correct Answer

Only a few data items organized in an array, accessible quickly without database overhead

Explanation

A mock object simulating a database may have only a few data items organized in an array. They can be accessed quickly without the overheads of calling a real database and accessing disks. This dramatically speeds up test execution while maintaining the same interface as the real database object.

Reference

Software Engineering, Ian Sommerville, 10th edition


Quizzes you can take where this question appears