Loading
Current section: Assertions 7 exercises
lesson

Assertions Introduction

Assertions are at the heart of every test—they capture your true expectations of the system. In this block, you’ll go beyond the basics: creating custom matchers and equality testers, improving failure messages for faster debugging, and expressing expectations toward eventual states in a more natural way.

Loading lesson

Transcript

00:00 Now that we've covered custom fixtures, it's time for us to talk about other ways to customize your test experience. And in this exercise block, you and I are going to focus on the most important part of any test. Assertions. In the heart of any assertion lies a matcher, a function that helps you describe your expectations. Functions like to be, to equal,

00:19 to match object, to throw, and so forth. VTest already comes with a vast variety of built-in matchers that you can use, but you can also create your own. In fact, custom matchers is a great way to introduce the main specific requirements into your test suite. For example, if you're testing user authentication and it takes a few steps to determine if the user

00:37 is in the right state, instead of repeating those steps in every test, you can introduce your custom matcher code to be authenticated and move all the authentication logic into that matcher. You're probably starting to notice a pattern here. Customizing your test experience helps you be both descriptive and declarative in your tests, as well as offload the complexity

00:55 of a tested system to where it belongs in the test setup. And in addition to custom matchers, we're going to cover some of the ways to help you describe your expectations in tests, things like soft and attributable assertions, as well as custom equality testers. This is a lot of material, so I hope you're ready, and let's go!