Search⌘ K
AI Features

Testing Delete Operation

Understand how to write and run tests for the delete function in Ecto queries using ExUnit. This lesson guides you through verifying successful deletion and ensuring data integrity in your Elixir application database.

We'll cover the following...

The delete function

Our last function, delete/1, is simple to test, as the code is a straight pass-through to Repo.delete/1.

Let’s look at the function:

Elixir
#file path -> testing_ecto/lib/users/users.ex
#add this code at the indicated place mentioned in comments of testing_ecto/lib/users/users.ex
#in the playground widget
def delete(%User{} = user) do
Repo.delete(user)
end

Tests

We’ll only test the success path for this function ...