My first attempt using meta programming on Elixir, that expand unit testing to support data provider on tests.
I intend to add more features to it and maybe make a package for it.
Please, any suggestion let me know to improve it.
Example:
defmodule ExTestCaseTests do
use ExUnit.Case
use ExTestCase
@data_provider [
[true, true],
[30, 12]
]
test "data provider using static data", input, expected do
assert input == expected
end
@data_provider get_data_provider(30)
test "data provider using a function", input, expected do
assert input == expected
end
def get_data_provider(value) do
[
[true, true],
[20, value],
[1, 1]
]
end
end
If you want to override @ to capture the unevaluated expression passed to @data_provider, it’s better to check specifically for that case instead of overriding the behavior for all module attributes.
Enum.join expects that its argument’s elements will be convertible using the String.Chars protocol; that’s not true for either maps or tuples. Consider mapping over the arguments with inspect first to generate human-readable values.
The extra dot-printing on line 42 works in the default ExUnit configuration, but it’s possible to turn colors off or even replace ExUnit.CLIFormatter entirely
Parting thought: if one of the tests from static data fails, how would a user run just that test case (versus running all of the cases generated by a single test macro)?
Thank you so much for ur suggestions, already commited with the fixes and improvements.
Regarding your last question, ye, it is a problem this test case helper has. Since I am using it as just a helper, I think its pretty much useful already.