Testing Schema Integrations with Database
Learn how to test schema through database calls.
While we have a decent basic schema defined, we haven’t covered a subset of the kinds of logic that we’ll find in changeset functions (code that requires interaction with the database to verify that it works).
The validations we’ve tested so far have laid out a pattern for us that can be used with other validations beyond cast/3
and validate_required/2
. Functions your code can call that can be tested in similar ways include (but are not limited to) validate_inclusion/4
, validate_length/3
, and validate_subset/4
.
A very common case where things are easier to test with a database is when there is a unique constraint on a column in our database.
Get hands-on with 1400+ tech skills courses.