有没有办法在 Erlang/OTP 中使用 Eunit 仅在单个模块中运行单元测试?

发布于 2024-12-27 02:36:24 字数 222 浏览 2 评论 0 原文

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

该模块的相关部分如下所示:

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

second_test() ->
  ...
  ...

I have a number of modules with unit tests. Is there a way of only running unit tests in a single module?

This is what the relevant section of the module looks like:

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

second_test() ->
  ...
  ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

寂寞美少年 2025-01-03 02:36:24

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

$ rebar3 eunit --module=mod1,mod2,mod3

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

$ rebar3 eunit --test=mod1:test1+test2,mod2:test1

参考文献:

https://rebar3.org/docs/testing/eunit/

Run all tests in the module/suite (as iuriza's answer):

$ rebar3 eunit --module=mod1,mod2,mod3

Or you can also specify an individual test case (by function name):

$ rebar3 eunit --test=mod1:test1+test2,mod2:test1

References:

https://rebar3.org/docs/testing/eunit/

∞梦里开花 2025-01-03 02:36:24

eunit:test(yourmodule)yourmodule:test() 应该可以工作。

eunit:test(yourmodule) or yourmodule:test() should work.

予囚 2025-01-03 02:36:24

如果您使用的是 rebar3,您可以根据其 运行测试 doc.

rebar3 eunit --module=your_module

如果您有大量模块,但只想运行其中几个模块的测试,则可以用逗号分隔名称:

rebar3 eunit --module=first_module,second_module,third_module

文档中有很多关于将测试运行限制为单个应用程序、文件等的提示。

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.

一口甜 2025-01-03 02:36:24

您还可以使用:

rebar clean eunit suite=your_module

You could also use:

rebar clean eunit suite=your_module
盛夏尉蓝 2025-01-03 02:36:24

改进 Adam Linberg 的响应,我做了:

rebar3 as test shell

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

eunit:test(yourmodule)

yourmodule:test()

Improving on the response from Adam Linberg, I did:

rebar3 as test shell

which makes possible to compile unit test files. Then you can type:

eunit:test(yourmodule)

or

yourmodule:test()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文