I have a test case with a setup and multiple tests. I want to run the exact same tests a couple times, changing a variable each time. In Rspec, this is trivial with let and shared_examples. ExUnit.Parameterized looks like it applies to individual test cases but not to the entire set of tests. What’s the right way to accomplish this in ExUnit?
%{1 => 2, 2 => 3}
|> Enum.each(fn {input, exp} ->
test "#{input} increased by one is #{exp}" do
assert unquote(exp) = 1 + unquote(input)
end
end)
For some more complex input values, you might need to unquote(Macro.escape(…)), but you’ll figure this one out as soon as ecto barfs at you because its unable to unquote something.
I do not like having many asserts in a single test.
Especially for such things. If you to a --trace or otherwise try to get a list of slow test, than very simple tests with a lot of different input might appear as slow tests, but in fact its not one slow test, but thousand fast ones.
But I think this is really a matter of personal taste.