从Erlang的Eunit获得测试结果 [英] Getting test results from Eunit in Erlang
问题描述
我正在与Erlang和EUnit一起进行单元测试,我想编写一个测试运行器来自动执行单元测试。问题是,eunit:test / 1似乎只返回错误或ok,而不是一个测试列表,以及他们通过或失败的方式返回的内容。
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 eunit
Rebar将编译并运行 test
目录中的所有测试(以及模块中的eunit测试)。此外,钢筋允许您在 rebar.config
中设置与shell相同的选项:
Rebar will compile and run all tests in the test
directory (as well as eunit tests inside your modules). Furthermore, rebar allows you set the same options in the rebar.config
as in the shell:
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
您还可以在shell中使用这些选项:
You can use these options also in the shell:
> eunit:test([foo], [verbose, {report,{eunit_surefire,[{dir,"."}]}}]).
另一种选择是使用Common Test而不是Eunit。通用测试带有一个运行器( ct_run
命令),并为您提供了更多的测试设置的灵活性,但使用起来也更复杂一些。普通测试缺少可用的宏,但产生非常可理解的html报告。
An alternative option would be to use Common Test instead of Eunit. Common Test comes with a runner (ct_run
command) 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.
这篇关于从Erlang的Eunit获得测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!