Often, I encounter the following bug in my tests:
property "test database", [], ctx do
forall row_to_be_inserted = %schema{} <- gen_row() do
Ecto.insert(row_to_be_inserted, ctx.repo)
match([%schema{}], Ecto.all(schema))
end
end
The bug is that upon multiple iterations of forall, the database is polluted with test data and the property fails because of side effects introduced in earlier iterations.
One possibility is to clean up manually like this:
property "test database", [], ctx do
forall row_to_be_inserted = %schema{} <- gen_row() do
Ecto.delete_all(schema)
Ecto.insert(row_to_be_inserted, ctx.repo)
match([%schema{}], Ecto.all(schema))
end
end
But this is tedious when doing it in many similar tests, especially if the database setup changes. It would be nice if there was a hook similar to ExUnit's on_exit which is called at the end or at the beginning of every forall in every property, and can be configured per module. This hook could then do the cleanup in one central place.
Often, I encounter the following bug in my tests:
The bug is that upon multiple iterations of
forall, the database is polluted with test data and the property fails because of side effects introduced in earlier iterations.One possibility is to clean up manually like this:
But this is tedious when doing it in many similar tests, especially if the database setup changes. It would be nice if there was a hook similar to
ExUnit'son_exitwhich is called at the end or at the beginning of everyforallin every property, and can be configured per module. This hook could then do the cleanup in one central place.