🧪Mock (Testing)
Also known as Mock, Mock Object, Mocking
A fake part that records how your code called it, so a test can check.
Think of it like
Think of it like a toy phone. It writes down each number you dial.
Example
Emma's test gives her sign-up code a mock email sender. The test then checks the mock was called once, with emma@example.com.
Why it matters
Some results never come back as a value, like an email sent. A mock lets you check them anyway.
Definition
Example code
python
send = Mock()
send("emma@example.com")
send.assert_called_once_with("emma@example.com")Common mistake
Key takeaways
- 1Records calls. Who, how often, with what.
- 2Checked after. The test asks the mock.
- 3Tests side effects. Without the real effect.