【问题标题】:Is there a way of only running unit tests in a single module using Eunit in Erlang/OTP?有没有办法在 Erlang/OTP 中使用 Eunit 仅在单个模块中运行单元测试?
【发布时间】:2012-02-11 15:29:35
【问题描述】:

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

这是模块的相关部分的样子:

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

second_test() ->
  ...
  ...

【问题讨论】:

标签: erlang eunit


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    你也可以使用:

    rebar clean eunit suite=your_module
    

    【讨论】:

      【解决方案3】:

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

      rebar eunit suite=mod_name
      

      或者你也可以指定一个单独的测试用例(通过函数名):

      rebar eunit tests=mod_name:test_name
      

      参考资料:

      【讨论】:

        【解决方案4】:

        如果您使用的是rebar3,则可以根据他们的Running Tests 文档使用--module 选项。

        rebar3 eunit --module=your_module
        

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

        rebar3 eunit --module=first_module,second_module,third_module
        

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

        【讨论】:

          【解决方案5】:

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

          rebar3 as test shell
          

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

          eunit:test(yourmodule)
          

          yourmodule:test()
          

          【讨论】:

            猜你喜欢
            • 2021-08-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-12-05
            • 1970-01-01
            • 1970-01-01
            • 2015-01-21
            • 2019-02-10
            相关资源
            最近更新 更多