Testing an Ecto Schema
Learn how to update our tests to test for interactivity with the database.
We'll cover the following...
Updating our tests
Now, we need to add :id
, :inserted_at
, and :updated_at
into the test’s schema definition. Update the @expected_fields_with_types
to include the new fields:
Press + to interact
#file path -> testing_ecto/test/schemas/user_database_schema_test.exs#add the highlighted code at the indicated place mentioned in comments of testing_ecto/#test/schemas/user_database_schema_test.exs in the playground widget@expected_fields_with_types [{:id, :binary_id},{:date_of_birth, :date},{:email, :string},{:favorite_number, :float},{:first_name, :string},{:inserted_at, :utc_datetime_usec},{:last_name, :string},{:phone_number, :string},{:updated_at, :utc_datetime_usec}]
After that, the fields and types
test should pass, but what if we run the whole file? Run the following command:
Press + to interact
mix test test/schemas/user_database_schema_test.exs
It will now yield errors that we haven’t seen yet. Those errors will be for the success test, and the test on casting errors, and the output for both will ...