Search the courses, subjects, tracks, games and features, or jump straight to a page.
3 cards from this section. Quick, good the night before a test.
What is mocking primarily used for in unit testing?
Think about why we need tests to be predictable.
Why should mocks be reset between tests?
What happens if one test affects another?
What is the main purpose of mocking?
Consider what dependencies can affect test outcomes.
True or False: Mocking allows tests to run independently of the actual implementation.
What advantages does independence provide in testing?
Create a function to get user data from an API and write a test that mocks the API response using patch.
Ensure your test verifies that the function handles the mocked response correctly.
You have a class with a method that relies on an external database connection. How would you write a test to ensure this method works without hitting the real database?
Consider the patterns of data the method expects and how to simulate those.
5 more questions in this section. Enroll free to practise them all.
Enroll free