...

/

Providing Test Data with Fixtures

Providing Test Data with Fixtures

Let’s learn how to use fixtures to build our data.

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.

Using fixtures in our project

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:

Press + to interact
defstruct title: nil,
mastery: 3,
templates: %{ },
used: [ ],
current_question: nil,
record: %{ },
last_response: nil,
mastered: [ ]

We’ll need to set the first three fields:

  • mastery

  • templates

  • used

The rest are computed. The best way to populate the templates field is to call our add_template function with a set of template fields. That means our strategy is going to look something like this:

Press + to interact
build_quiz
|> add_template(template_fields_1)
|> add_template(template_fields_2)

Constructing our templates

Templates are also ...