Loading
Current section: Context 4 exercises
lesson

Context Introduction

In this section, we’ll look at how fixtures let you capture complex setup logic without letting it spill into your test cases.

You’ll see how creating your own reusable “bricks” makes tests easier to follow, more expressive, and resilient to change—all while keeping focus on the behavior you actually want to verify.

Loading lesson

Transcript

00:00 Have you ever been in a situation when you know enough about your system and now want to finally reflect that knowledge in tests? But the moment you open that test file and write the first test case, suddenly it feels like the whole world is against you. Like you have to fight just to get that single test in.

00:16 When that happens, that is often a sign of complexity leaking from your application into your test suite. Because truth be told, the software you build in may get quite complex. It rarely exists in isolation and instead is a part of a larger system. It has dependencies and acts like one for something else. And to a certain degree, that complexity is inevitable in your tests.

00:35 Like when you're testing a function that has 10 different behaviors, you will end up writing 10 different test cases for those behaviors, and maybe even a few more to test how those behaviors interact with each other. And that is fine. The problem starts when you let in more complexity than necessary.

00:51 And suddenly, all you wanted to do was write a simple test for this particular behavior, but you end up fighting all the dependencies, all the side effects, and all the other things that your application does. So despite that complexity being there, your test case isn't the right place to address it. Because there is a much better way.

01:08 There is the test setup, designated to addressing all of that complexity. Unfortunately, the test setup ends up being one of the overlooked and underloved steps of defining your testing strategy. Testers often miss how crucial it is to just sit down and design the right experience,

01:26 experience specific to the application that you're going to be testing. So every further test case ends up being simpler. Because a properly orchestrated test case feels like putting the bricks together. This behavior happened to depend on a dependency. Here's a function that helps you handle that. It establishes a database connection.

01:44 There is another utility that helps you mock that connection, or perhaps connect to a test database, and so on. The importance of the test setup cannot be overstated. So in this exercise blog, we're going to focus on one of the ways how to bring your test setup to the next level. You will learn how to create your custom utilities or fixtures in VTEST, and use them to test

02:03 your application efficiently, and also deal with the complexity introduced by your application. So I hope you're excited. Let's go.