Prime Tests with Named Setups
You’ve just seen the first type of setup function, fixtures. In this section, we’ll cover the next kind of reusable setup function, ExUnit’s named setup feature. To understand how it works, let’s take a more detailed look at the flow of a typical ExUnit testcase.
In version 1.3 of Elixir, the ExUnit.Case module added a describe block. Tests within a block could share common setup code. When you specified a block of tests within a describe, you could also specify the names of one or more functions to create common setup data. Here’s how that would look, in our test layer:
You can see how tests with describe work. ...
Get Designing Elixir Systems With OTP now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.