Prime Tests with Named Setups

An introduction to named setups, another setup function that Elixir uses to test data.

We’ve just seen the first type of setup function—fixtures. We’ll cover the next kind of reusable setup function in the following lessons, ExUnit’s named setup feature. To understand how it works, let’s take a more detailed look at the flow of a typical ExUnit test case.

Describe blocks

In version 1.3 of Elixir, the ExUnit.Case module added a describe block that has the following properties:

  • Tests within a block can share a common setup code.

  • When we specify a block of tests within a describe, we can also set the names of one or more functions to create common setup data.

Here’s how that would look in our test layer:

Get hands-on with 1200+ tech skills courses.