Skip to content

Fake

In one line

A fake is a test double with real but simplified behavior — e.g., an in-memory database instead of a real PostgreSQL instance.

In simple words

A fake is a test double that actually works — it has real logic, just simplified. Unlike a stub (which returns canned values) or a mock (which verifies calls), a fake implements the same interface as the real thing but in a simpler way.

The most common example is an in-memory database. Instead of connecting to a real PostgreSQL database (slow, needs setup, might have side effects), you use a fake that stores data in a JavaScript Map. It has the same methods (insert, find, update, delete) and they work correctly — it's just not persistent and doesn't need a server.

Fakes are useful for integration testing: they're fast like mocks but test real behavior like the actual dependency. The risk is that the fake might not perfectly match the real implementation's behavior, especially for edge cases.

Example

javascript
// Fake database
class FakeDb {
  constructor() { this.data = new Map(); }
  insert(id, record) { this.data.set(id, record); }
  findById(id) { return this.data.get(id); }
}
// Works like a real DB but in memory — fast, no setup

The fake database has real CRUD logic but stores data in memory instead of a real database.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary