Promptles
Testing & Quality

Mock

intermediate

Definition

A pretend version of something the code normally talks to, a database, an email service, a payment processor, used during tests. The mock behaves the way the test wants and quietly records what the code asked it to do, so the test can check that the right things happened.

In the wild

A test wants to check that 'when a user signs up, a welcome email gets sent.' It doesn't actually want to send a real email every time it runs. So it gives the code a mock email service. Afterwards, the test asks the mock: 'were you asked to send an email to alice@example.com?' If yes, the test passes.

More from Testing & Quality