Skip to content
BENIBIX Learn

Fake (Testing)

Development🧪 Testing & QualityTest Doubles

Also known as Fake, Fake Object, In-Memory Fake

A small copy of a real part. It works, but only in tests.

Think of it like

Think of it like a toy kitchen. You can really cook pretend food, but it is not a real stove.

Example

Jack's tests use a fake user store that keeps users in a list. 500 tests run in 2 seconds, with no database to start.

Why it matters

Fakes let lots of tests run fast. They still act like the real part, not just give one set answer.

Definition

A fake is a test double that really works, but in a simple, cheap way. A common one is an in-memory database that keeps data in a list instead of on disk. It behaves like the real thing for the cases your tests need. It is much faster and needs no set-up. Fakes are not fit for real use, because they skip things like safety and saving data for good.

Common mistake

Letting the fake drift from the real thing. Run the same few tests against both now and then.

Key takeaways

  1. 1
    Really works. In a simple way.
  2. 2
    Fast and cheap. Often kept in memory.
  3. 3
    Tests only. Never for real use.

Compare