Reputation: 2176
I have a module of tests that run synchronized one after the other.
I would like to clean all the changes done on the db by the tests after all tests complete, i.e. I want the data to persist in the db between one test to another.
My app is using a PostgreSQL database (MyRepo
).
when I use Ecto.Adapters.SQL.Sandbox.checkout(MyRepo)
in the setup_all
function the DB gets cleaned after each test.
This is my condig/test.exs
file:
config :my_repo, MyRepo,
pool: Ecto.Adapters.SQL.Sandbox,
database: "my-repo-test",
username: "postgres",
password: "postgres",
hostname: "localhost",
port: "5432",
pool_size: 1,
max_overflow: 0,
What is the right way to do it?
Upvotes: 1
Views: 1322
Reputation: 120990
You might use ExUnit.Callbacks.on_exit/2
:
setup_all do
on_exit fn -> Repo.cleanup() end
end
Upvotes: 2