What Do We Need Mocks For?

Learn about the different types of test doubles and how we can use them.

Until now, we’ve been testing small components in isolation as much as possible. Unit testing is essentially about testing units of code (classes, objects, and so on) without any interaction with the rest of the codebase. The problem is that often our units need other units to work. In this lesson, we’re going to discuss a couple of testing styles to limit, as much as possible, interaction between the unit under test and other units.

State testing vs. behavior testing

When it comes to testing units together, we have two major ways to design our tests: state verification and behavior verification. To show their differences, let’s add a new feature to our small program: the possibility of publishing a course. A course can be published only if it has more than one lesson.

Get hands-on with 1400+ tech skills courses.