Vlad
Vlad

Reputation: 31

Pass the same parameter to multiple tests

How do I pass the same parameter to different tests in Elixir? Now I calculate it in every test. Is it possible to calculate this parameter once before starting tests and pass it to each test?

Upvotes: 2

Views: 410

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

Use ExUnit.Callbacks.setup/1 or ExUnit.Callbacks.setup_all/1

setup_all do
  [my_param: 42]
end

test "global context", %{my_param: value} do
  assert 42 == value
end

Upvotes: 4

Related Questions