Creating a Factory
Learn how to create factories for our setup, and how to use datacase for database interactions.
Why do we need to create factories?
In testing, we create factories to give consistent, repeatable ways to provide data for our setup phase.
When we write tests that interact with database tables, we need two sets of data that are either valid or invalid with regard to the table’s definition. As our applications grow larger, we’ll find that having a single source of setup data helps us keep the test suite maintainable. If we update our schema definition, that single source is often the only place (aside from the tests for the schema file itself) that’ll need to be updated in our test suite.
Creating factories from scratch
It’s totally possible to write a factory for our application entirely from scratch. Let’s roll back our memory.
When we were testing our Ecto schemas, we started by creating a helper ...