有没有办法在erlang中使用Eunit在单个模块中运行单元测试?

时间:2012-01-16 18:02:11

标签: erlang eunit

我有许多单元测试模块。 有没有办法只在单个模块中运行单元测试。

这就是模块的相关部分:

-export([ ..... ])
-include_lib("eunit/include/eunit.hrl").
...
...
...
first_test() ->
  ...
  ...

second_test() ->
  ...
  ...

(当然,测试的名称不是第一和第二。)

5 个答案:

答案 0 :(得分:4)

在模块/套件中运行所有测试(作为iuriza的答案):

rebar eunit suite=mod_name

或者您也可以指定单个测试用例(按功能名称):

rebar eunit tests=mod_name:test_name

参考文献:

答案 1 :(得分:3)

eunit:test(yourmodule)yourmodule:test()应该有效。

答案 2 :(得分:1)

If you're using rebar3 you can use the --module option per their Running Tests doc.

rebar3 eunit --module=your_module

If you have tons of modules, but only want to run tests for a few of them, you can separate the names with commas:

rebar3 eunit --module=first_module,second_module,third_module

The documentation has a lot of tips for limiting the tests run to a single application, file, etc.

答案 3 :(得分:0)

你也可以使用:

rebar clean eunit suite=your_module

答案 4 :(得分:0)

改进了 Adam Linberg 的回复,我做到了:

rebar3 as test shell

这使得编译单元测试文件成为可能。然后你可以输入:

eunit:test(yourmodule)

yourmodule:test()
相关问题