For anyone else that comes across this as an example of data-driven tests and wants to improve their test reporting output you can do something like the following:
test "stem transformations" do
input_list = String.split(File.read!("test/data/voc.txt") , "\n")
output_list = String.split(File.read!("test/data/output.txt"), "\n")
io_list = List.zip([input_list, output_list])
for {input, output} <- io_list do
actual = StemEx.stem(input)
message = """
StemEx.stem(
input = #{inspect input}
)
was expected to output #{output} but instead was #{actual}
"""
assert actual == output, message
end
end
This will give you pretty output like:
1) test stem transformations (StemExTest)
test/stem_ex_test.exs:10
StemExTest.stem(
input = "some input"
)
was expected to equal false but instead was true
Whereas the default output show something more like:
Assertion with == failed
code: StemExTest.stem(input) == output
left: true
right: false
Which isn’t that helpful since you can’t tell what the input is without adding some IO.puts into your test code. There’s probably more elegant ways to accomplish what I’m outlining but I think this is at least a good start!






















