Testing Your Schema Through Changesets

As we mentioned, Ecto can be used for more than just database interactions, the most common case being as a validator of data. Either way you use it, there’s a common core of code in the schema file and therefore there are common tests. We’ll start by testing that common code, and then we’ll make some refactors to make our tests easier to maintain. After that, we’ll branch out and refactor our code and tests twice, once for each use case. We’ll call it out when it happens. This means that we’ll be working in very similar code but switching between file names to keep the concepts separate.

Our Ecto-based code and tests are going to be written to reflect the belief that schema files should contain a bare ...

Get Testing Elixir 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.