From the course: Unit Testing and Test Driven Development in Python

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Test doubles, unittest.mock, and monkeypatch overview

Test doubles, unittest.mock, and monkeypatch overview - Python Tutorial

From the course: Unit Testing and Test Driven Development in Python

Test doubles, unittest.mock, and monkeypatch overview

- [Narrator] In this lecture, I'm going to go over how you can make sure you're running your unit tests in isolation using the concepts of dummies, fakes, stubs, spies, and Mocks. So what are test doubles? Almost all code that gets implemented will depend on another piece of code in the system. Those other pieces of code are often times trying to do things or communicate with things that are not available in the unit testing environment, or are so slow they would make our unit tests extremely slow. For example, if your code queries a third-party rest API on the internet, and that server is down for any reason, you can't run your test. Test doubles are the answer to that problem. They are objects that are created in the test to replace the real production system collaborators. There are many types of test doubles. Dummy objects are the simplest. They are simply placeholders that are intended to be passed around but not actually called or used in any real way. They'll often generate…

Contents