Creating a SchemaCase for Shared Test Code
Learn how to use our schema as data validation code.
Case template
Case templates are handy when identifying a pattern for test files that would benefit from shared code. Our refactors on the basic schema tests created two helper functions, valid_params/1
and invalid_params/1
, that would be good to move into a common place to be reused by all our schema tests.
We’ll create a case template called SchemaCase
and move the helper functions there. Let’s start by creating a new file called testing_ecto/test/schema_case.ex
and add the basic structure for a case template:
Press + to interact
#file path -> testing_ecto/test/schema_case.ex#add this code at the indicated place mentioned in comments of testing_ecto/test/schema_case.ex#in the playground widgetuse ExUnit.CaseTemplateusing doquote doalias Ecto.Changesetimport TestingEcto.SchemaCaseendend
For now, ...
Get hands-on with 1400+ tech skills courses.