Refactoring Tests to Be Self-updating
Learn how to write self-updating tests for a basic schema.
We'll cover the following...
Now that we have guaranteed our test’s accuracy in the previous lesson let’s refactor our test to be self-updating.
Creating a self-updating test
Before we write our first test, we’ll write a helper function at the bottom of our test file after all the describe blocks.
Helper function
The new function will be called valid_params/1:
The return value of this function is a map that’s functionally identical to the params we had in our success test in our previous iteration of this file (user_basic_schema_1_test.exs). It’s just a string-keyed map of valid parameters, but it’s built dynamically based on the list of fields and types passed to it.
Faker
We’re using a new library, Faker:
Faker’s sole purpose is to provide realistically shaped data, often to use as fake data for ...