Provide Test Data with Fixtures

We’ll focus on fixtures in this section. Recall that in our functional core, test fixtures are functions that create data so we can write repeatable tests without the extra ceremony. Our quizzes are complex, so the job of our fixtures is to focus on building data—the various structs and maps that make up our data layer—so we can keep those details out of the tests.

Recall that our quizzes have the following structure:

 defstruct ​title:​ nil,
 mastery:​ 3,
 templates:​ %{ },
 used:​ [ ],
 current_question:​ nil,
 record:​ %{ },
 last_response:​ nil,
 mastered:​ [ ]

We’ll need to set those first three fields. The rest are computed. The best way to populate the templates field is to call our add_template ...

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.