Mocking Dependencies

Learn how to refactor code and mock dependencies.

When we write a unit test, we need to isolate our component that is being tested. We do this by faking or mocking parts of the system that it interacts with. There are several techniques we can use, including stubs, mocks, spies, and staging services. This lets us write focused unit tests that run fast and give us useful, targeted feedback in the event that they fail.

Get hands-on with 1200+ tech skills courses.