I am working with Erlang and EUnit to do unit tests, and I would like to write a test runner to automate the running of my unit tests. The problem is that eunit:test/1 seems to only return “error” or “ok” and not a list of tests and what they returned in terms of what passed or failed.
So is there a way to run tests and get back some form of a data structure of what tests ran and their pass/fail state?
If you are using rebar you don’t have to implement your own runner. You can simply run:
Rebar will compile and run all tests in the
testdirectory (as well as eunit tests inside your modules). Furthermore, rebar allows you set the same options in therebar.configas in the shell:You can use these options also in the shell:
See also documentation for verbose option and structured report.
An alternative option would be to use Common Test instead of Eunit. Common Test comes with a runner (
ct_runcommand) and gives you more flexibility in your test setup but is also a little more complex to use. Common Test lacks on the available macros but produces very comprehensible html reports.