Among many of the tests in our codebase there is a setup repeated multiple times, which is basically starting some required processes (mainly Registries) and looks something like this:
setup do
start_supervised(MyApp.MyModule.Supervisor)
start_supervised({Registry, keys: :unique, name: MyApp.Registry.ById})
...
:ok
end
I want to extract this in a common module so it can be used easier.
My idea was something like this:
- Create a module with setup functions under
test/support
- Import the module on the required test
- Call them with in the test setup like
setup :set_my_registries
(like defined here
The problem is that the start_supervised
function is of course not defined in my module.
My questions are:
- Can I import/require something from ExUnit to make it work?
- Should I try to hack it using Macros and
use
it in the test? - Is there a better approach?
PS: I know the philosophy in Elixir tests is to be descriptive but is very annoying when something change names or now there is another dependency and added in all the setup blocks